Phoenix Logo

phoenix_title wx.lib.pdfviewer.viewer.pdfViewer

View pdf file in a scrolled window. Contents are read from PDF file and rendered in a GraphicsContext. Show visible window contents as quickly as possible then, when using pyPDF, read the whole file and build the set of drawing commands for each page. This can take time for a big file or if there are complex drawings eg. ReportLab’s colour shading inside charts and a progress bar can be displayed by setting self.ShowLoadProgress = True (default)


class_hierarchy Class Hierarchy

Inheritance diagram for class pdfViewer:

super_classes Known Superclasses

wx.ScrolledWindow


method_summary Methods Summary

__init__ Default class constructor.
CalculateDimensions Compute the required buffer sizes to hold the viewed rectangle and
GoPage Go to page
LoadFile Read pdf file. Assume all pages are same size, for now.
OnIdle Redraw on resize.
OnPaint Refresh visible window with bitmap contents.
OnResize Buffer size change due to client area resize.
OnScroll Recalculate and redraw visible area. CallAfter is essential
Print Print the pdf.
Render Recalculate dimensions as client area may have been scrolled or resized.
RenderPageBoundaries Show non-page areas in grey.
Save Save a copy of the pdf file if it was originally named
SetZoom Positive integer or floating zoom scale will render the file at corresponding

property_summary Properties Summary

ShowLoadProgress Property to control if file reading progress is shown (PyPDF2 only)

api Class API



class pdfViewer(wx.ScrolledWindow)

View pdf file in a scrolled window. Contents are read from PDF file and rendered in a GraphicsContext. Show visible window contents as quickly as possible then, when using pyPDF, read the whole file and build the set of drawing commands for each page. This can take time for a big file or if there are complex drawings eg. ReportLab’s colour shading inside charts and a progress bar can be displayed by setting self.ShowLoadProgress = True (default)


Methods



__init__(self, parent, nid, pos, size, style)

Default class constructor.

Parameters:
  • parent (wx.Window) – parent window. Must not be None;
  • nid (integer) – window identifier. A value of -1 indicates a default value;
  • pos (tuple or wx.Point) – the control position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxPython, depending on platform;
  • size (tuple or wx.Size) – the control size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxPython, depending on platform;
  • style (integer) – the button style (unused);


CalculateDimensions(self)

Compute the required buffer sizes to hold the viewed rectangle and the range of pages visible. Set self.page_buffer_valid = False if the current set of rendered pages changes



GoPage(self, pagenum)

Go to page

Parameters:pagenum (integer) – go to the provided page number if it is valid


LoadFile(self, pdf_file)

Read pdf file. Assume all pages are same size, for now.

Parameters:pdf_file – can be either a string holding

a filename path or a file-like object.



OnIdle(self, event)

Redraw on resize.



OnPaint(self, event)

Refresh visible window with bitmap contents.



OnResize(self, event)

Buffer size change due to client area resize.



OnScroll(self, event)

Recalculate and redraw visible area. CallAfter is essential for coordination.



Print(self, prompt=True, printer_name=None, orientation=None)

Print the pdf.

Parameters:
  • prompt (boolean) – show the print dialog to the user (True/False). If False, the print dialog will not be shown and the pdf will be printed immediately. Default: True.
  • printer_name (string) – the name of the printer that is to receive the printout. Default: as set by the O/S.
  • orientation – select the orientation (wx.PORTRAIT or wx.LANDSCAPE) for the printout. Default: as set by the O/S.


Render(self)

Recalculate dimensions as client area may have been scrolled or resized. The smallest unit of rendering that can be done is the pdf page. So render the drawing commands for the pages in the visible rectangle into a buffer big enough to hold this set of pages. Force re-creating the page buffer only when client view moves outside it. With PyPDF2, use gc.Translate to render each page wrt the pdf origin, which is at the bottom left corner of the page.



RenderPageBoundaries(self, gc)

Show non-page areas in grey.



Save(self)

Save a copy of the pdf file if it was originally named



SetZoom(self, zoomscale)

Positive integer or floating zoom scale will render the file at corresponding size where 1.0 is “actual” point size (1/72”). -1 fits page width and -2 fits page height into client area Redisplay the current page(s) at the new size

Parameters:zoomscale – an integer or float

Properties



ShowLoadProgress

Property to control if file reading progress is shown (PyPDF2 only)