Table Of Contents

Previous topic

PrintOrientation

Next topic

Printer

This Page

phoenix_title PrintPreview

Objects of this class manage the print preview process.

The object is passed a Printout object, and the PrintPreview object itself is passed to a PreviewFrame object. Previewing is started by initializing and showing the preview frame. Unlike Printer.Print , flow of control returns to the application immediately after the frame is shown.

Note

The preview shown is only exact on Windows. On other platforms, the DC used for preview is different from what is used for printing and the results may be significantly different, depending on how is the output created. In particular, printing code relying on DC.GetTextExtent heavily (for example, HtmlEasyPrinting and other HTML classes do) is affected. It is recommended to use native preview functionality on platforms that offer it (OS X, GTK+).


class_hierarchy Inheritance Diagram

Inheritance diagram for class PrintPreview

Inheritance diagram of PrintPreview


method_summary Methods Summary

__init__ Constructor.
GetCanvas Gets the preview window used for displaying the print preview image.
GetCurrentPage Gets the page currently being previewed.
GetFrame Gets the frame used for displaying the print preview canvas and control bar.
GetMaxPage Returns the maximum page number.
GetMinPage Returns the minimum page number.
GetPrintout Gets the preview printout object associated with the PrintPreview object.
GetPrintoutForPrinting Gets the printout object to be used for printing from within the preview interface, or None if none exists.
IsOk Returns True if the PrintPreview is valid, False otherwise.
PaintPage This refreshes the preview window with the preview image.
Print Invokes the print process using the second Printout object supplied in the PrintPreview constructor.
RenderPage Renders a page into a MemoryDC.
SetCanvas Sets the window to be used for displaying the print preview image.
SetCurrentPage Sets the current page to be previewed.
SetFrame Sets the frame to be used for displaying the print preview canvas and control bar.
SetPrintout Associates a printout object with the PrintPreview object.
SetZoom Sets the percentage preview zoom, and refreshes the preview canvas accordingly.
__nonzero__  

api Class API



class PrintPreview(Object)

Objects of this class manage the print preview process.

Possible constructors:

PrintPreview(printout, printoutForPrinting=None, data=None)

PrintPreview(printout, printoutForPrinting, data)

Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self, printout, printoutForPrinting=None, data=None)

Constructor.

Pass a printout object, an optional printout object to be used for actual printing, and the address of an optional block of printer data, which will be copied to the print preview object’s print data.

If printoutForPrinting is not None, a “Print...” button will be placed on the preview frame so that the user can print directly from the preview interface.

Use IsOk to check whether the PrintPreview object was created correctly.

Parameters:

Note

Do not explicitly delete the printout objects once this constructor has been called, since they will be deleted in the PrintPreview destructor. The same does not apply to the data argument.



__init__ (self, printout, printoutForPrinting, data)

Parameters:





GetCanvas(self)

Gets the preview window used for displaying the print preview image.

Return type: PreviewCanvas


GetCurrentPage(self)

Gets the page currently being previewed.

Return type:int


GetFrame(self)

Gets the frame used for displaying the print preview canvas and control bar.

Return type: Frame


GetMaxPage(self)

Returns the maximum page number.

Return type:int


GetMinPage(self)

Returns the minimum page number.

Return type:int


GetPrintout(self)

Gets the preview printout object associated with the PrintPreview object.

Return type: Printout


GetPrintoutForPrinting(self)

Gets the printout object to be used for printing from within the preview interface, or None if none exists.

Return type: Printout


IsOk(self)

Returns True if the PrintPreview is valid, False otherwise.

It could return False if there was a problem initializing the printer device context (current printer not set, for example).

Return type:bool


PaintPage(self, canvas, dc)

This refreshes the preview window with the preview image.

It must be called from the preview window’s OnPaint member.

The implementation simply blits the preview bitmap onto the canvas, creating a new preview bitmap if none exists.

Parameters:
Return type:

bool



Print(self, prompt)

Invokes the print process using the second Printout object supplied in the PrintPreview constructor.

Will normally be called by the Print... panel item on the preview frame’s control bar.

Returns False in case of error – call Printer.GetLastError to get detailed information about the kind of the error.

Parameters:prompt (bool) –
Return type:bool


RenderPage(self, pageNum)

Renders a page into a MemoryDC.

Used internally by PrintPreview.

Parameters:pageNum (int) –
Return type:bool


SetCanvas(self, window)

Sets the window to be used for displaying the print preview image.

Parameters:window (PreviewCanvas) –


SetCurrentPage(self, pageNum)

Sets the current page to be previewed.

Parameters:pageNum (int) –
Return type:bool


SetFrame(self, frame)

Sets the frame to be used for displaying the print preview canvas and control bar.

Parameters:frame (Frame) –


SetPrintout(self, printout)

Associates a printout object with the PrintPreview object.

Parameters:printout (Printout) –


SetZoom(self, percent)

Sets the percentage preview zoom, and refreshes the preview canvas accordingly.

Parameters:percent (int) –


__nonzero__(self)
Return type:int

Properties



Canvas

See GetCanvas and SetCanvas



CurrentPage

See GetCurrentPage and SetCurrentPage



Frame

See GetFrame and SetFrame



MaxPage

See GetMaxPage



MinPage

See GetMinPage



Printout

See GetPrintout and SetPrintout



PrintoutForPrinting

See GetPrintoutForPrinting