wxPrintPreview — wx v2.4.2

Search documentation of wx

# View Source wxPrintPreview (wx v2.4.2)

Functions for wxPrintPreview class

Objects of this class manage the print preview process. The object is passed a `wxPrintout` object, and the `wxPrintPreview` object itself is passed to a `wxPreviewFrame` object. Previewing is started by initializing and showing the preview frame. Unlike `wxPrinter:print/4`, 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 `wxDC` 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 `wxDC:getTextExtent/3` heavily (for example, `wxHtmlEasyPrinting` and other wxHTML classes do) is affected. It is recommended to use native preview functionality on platforms that offer it (macOS, GTK+).

See: Overview printing, `wxPrinterDC` (not implemented in wx), `wxPrintDialog`, `wxPrintout`, `wxPrinter`, `wxPreviewCanvas`, `wxPreviewControlBar`, `wxPreviewFrame`

wxWidgets docs: wxPrintPreview

# Summary

## Types

wxPrintPreview()

## Functions

destroy(This)

Destructor.

getCanvas(This)

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

getCurrentPage(This)

Gets the page currently being previewed.

getFrame(This)

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

getMaxPage(This)

Returns the maximum page number.

getMinPage(This)

Returns the minimum page number.

getPrintout(This)

Gets the preview printout object associated with the `wxPrintPreview` object.

getPrintoutForPrinting(This)

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

isOk(This)

Returns true if the `wxPrintPreview` is valid, false otherwise.

new(Printout)
new/2

Constructor.

new(Printout, PrintoutForPrinting, Data)
paintPage(This, Canvas, Dc)

This refreshes the preview window with the preview image.

print(This, Prompt)

Invokes the print process using the second `wxPrintout` object supplied in the `wxPrintPreview` constructor.

renderPage(This, PageNum)

Renders a page into a `wxMemoryDC`.

setCanvas(This, Window)

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

setCurrentPage(This, PageNum)

Sets the current page to be previewed.

setFrame(This, Frame)

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

setPrintout(This, Printout)

Associates a printout object with the `wxPrintPreview` object.

setZoom(This, Percent)

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

# Types

Link to this type

# wxPrintPreview()

View Source

    -type wxPrintPreview() :: wx:wx_object().

# Functions

Link to this function

# destroy(This)

View Source

    -spec destroy(This :: wxPrintPreview()) -> ok.

Destructor.

Deletes both print preview objects, so do not destroy these objects in your application.

Link to this function

# getCanvas(This)

View Source

    -spec getCanvas(This) -> wxPreviewCanvas:wxPreviewCanvas() when This :: wxPrintPreview().

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

Link to this function

# getCurrentPage(This)

View Source

    -spec getCurrentPage(This) -> integer() when This :: wxPrintPreview().

Gets the page currently being previewed.

Link to this function

# getFrame(This)

View Source

    -spec getFrame(This) -> wxFrame:wxFrame() when This :: wxPrintPreview().

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

Link to this function

# getMaxPage(This)

View Source

    -spec getMaxPage(This) -> integer() when This :: wxPrintPreview().

Returns the maximum page number.

Link to this function

# getMinPage(This)

View Source

    -spec getMinPage(This) -> integer() when This :: wxPrintPreview().

Returns the minimum page number.

Link to this function

# getPrintout(This)

View Source

    -spec getPrintout(This) -> wxPrintout:wxPrintout() when This :: wxPrintPreview().

Gets the preview printout object associated with the `wxPrintPreview` object.

Link to this function

# getPrintoutForPrinting(This)

View Source

    -spec getPrintoutForPrinting(This) -> wxPrintout:wxPrintout() when This :: wxPrintPreview().

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

Link to this function

# isOk(This)

View Source

    -spec isOk(This) -> boolean() when This :: wxPrintPreview().

Returns true if the `wxPrintPreview` is valid, false otherwise.

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

Link to this function

# new(Printout)

View Source

    -spec new(Printout) -> wxPrintPreview() when Printout :: wxPrintout:wxPrintout().

Link to this function

# new/2

View Source

    -spec new(Printout, [Option]) -> wxPrintPreview()
                 when
                     Printout :: wxPrintout:wxPrintout(),
                     Option ::
                         {printoutForPrinting, wxPrintout:wxPrintout()} |
                         {data, wxPrintDialogData:wxPrintDialogData()}.

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 non-NULL, a `"Print..."` button will be placed on the preview frame so that the user can print directly from the preview interface.

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

Use `isOk/1` to check whether the `wxPrintPreview` object was created correctly.

Link to this function

# new(Printout, PrintoutForPrinting, Data)

View Source

    -spec new(Printout, PrintoutForPrinting, Data) -> wxPrintPreview()
                 when
                     Printout :: wxPrintout:wxPrintout(),
                     PrintoutForPrinting :: wxPrintout:wxPrintout(),
                     Data :: wxPrintData:wxPrintData().

Link to this function

# paintPage(This, Canvas, Dc)

View Source

    -spec paintPage(This, Canvas, Dc) -> boolean()
                       when
                           This :: wxPrintPreview(),
                           Canvas :: wxPreviewCanvas:wxPreviewCanvas(),
                           Dc :: wxDC:wxDC().

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.

Link to this function

# print(This, Prompt)

View Source

    -spec print(This, Prompt) -> boolean() when This :: wxPrintPreview(), Prompt :: boolean().

Invokes the print process using the second `wxPrintout` object supplied in the `wxPrintPreview` constructor.

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

Returns false in case of error - call `wxPrinter:getLastError/0` to get detailed information about the kind of the error.

Link to this function

# renderPage(This, PageNum)

View Source

    -spec renderPage(This, PageNum) -> boolean() when This :: wxPrintPreview(), PageNum :: integer().

Renders a page into a `wxMemoryDC`.

Used internally by `wxPrintPreview`.

Link to this function

# setCanvas(This, Window)

View Source

    -spec setCanvas(This, Window) -> ok
                       when This :: wxPrintPreview(), Window :: wxPreviewCanvas:wxPreviewCanvas().

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

Link to this function

# setCurrentPage(This, PageNum)

View Source

    -spec setCurrentPage(This, PageNum) -> boolean() when This :: wxPrintPreview(), PageNum :: integer().

Sets the current page to be previewed.

Link to this function

# setFrame(This, Frame)

View Source

    -spec setFrame(This, Frame) -> ok when This :: wxPrintPreview(), Frame :: wxFrame:wxFrame().

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

Link to this function

# setPrintout(This, Printout)

View Source

    -spec setPrintout(This, Printout) -> ok
                         when This :: wxPrintPreview(), Printout :: wxPrintout:wxPrintout().

Associates a printout object with the `wxPrintPreview` object.

Link to this function

# setZoom(This, Percent)

View Source

    -spec setZoom(This, Percent) -> ok when This :: wxPrintPreview(), Percent :: integer().

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