gtk-High-level-Printing-API {RGtk2} | R Documentation |
High-level Printing API
gtkPrintOperationNew()
gtkPrintOperationSetAllowAsync(object, allow.async)
gtkPrintOperationGetError(object, .errwarn = TRUE)
gtkPrintOperationSetDefaultPageSetup(object, default.page.setup = NULL)
gtkPrintOperationGetDefaultPageSetup(object)
gtkPrintOperationSetPrintSettings(object, print.settings = NULL)
gtkPrintOperationGetPrintSettings(object)
gtkPrintOperationSetJobName(object, job.name)
gtkPrintOperationSetNPages(object, n.pages)
gtkPrintOperationSetCurrentPage(object, current.page)
gtkPrintOperationSetUseFullPage(object, full.page)
gtkPrintOperationSetUnit(object, unit)
gtkPrintOperationSetExportFilename(object, filename)
gtkPrintOperationSetShowProgress(object, show.progress)
gtkPrintOperationSetTrackPrintStatus(object, track.status)
gtkPrintOperationSetCustomTabLabel(object, label)
gtkPrintOperationRun(object, action, parent = NULL, .errwarn = TRUE)
gtkPrintOperationCancel(object)
gtkPrintOperationGetStatus(object)
gtkPrintOperationGetStatusString(object)
gtkPrintOperationIsFinished(object)
gtkPrintOperationGetError(object, .errwarn = TRUE)
gtkPrintRunPageSetupDialog(parent, page.setup = NULL, settings)
gtkPrintRunPageSetupDialogAsync(parent, page.setup, settings, done.cb, data)
gtkPrintOperationPreviewEndPreview(object)
gtkPrintOperationPreviewIsSelected(object, page.nr)
gtkPrintOperationPreviewRenderPage(object, page.nr)
gtkPrintOperation()
GObject +----GtkPrintOperation GInterface +----GtkPrintOperationPreview
GtkPrintOperationPreview is implemented by
GtkPrintOperation
.
GtkPrintOperation implements
GtkPrintOperationPreview
.
GtkPrintOperation is the high-level, portable printing API. It looks
a bit different than other GTK+ dialogs such as the GtkFileChooser
,
since some platforms don't expose enough infrastructure to implement
a good print dialog. On such platforms, GtkPrintOperation uses the
native print dialog. On platforms which do not provide a native
print dialog, GTK+ uses its own, see GtkPrintUnixDialog
.
The typical way to use the high-level printing API is to create a
GtkPrintOperation
object with gtkPrintOperationNew
when the user
selects to print. Then you set some properties on it, e.g. the page size,
any GtkPrintSettings
from previous print operations, the number of pages,
the current page, etc.
Then you start the print operation by calling gtkPrintOperationRun
.
It will then show a dialog, let the user select a printer and options.
When the user finished the dialog various signals will be emitted on the
GtkPrintOperation
, the main one being ::draw-page, which you are supposed
to catch and render the page on the provided GtkPrintContext
using Cairo.
settings <- NULL print_something <- { op <- gtkPrintOperation() if (!is.null(settings)) op$setPrintSettings(settings) gSignalConnect(op, "begin_print", begin_print) gSignalConnect(op, "draw_page", draw_page) res <- op$run("print-dialog", main_window)[[1]] if (res == "apply") settings <- op$getPrintSettings() }By default GtkPrintOperation uses an external application to do print preview. To implement a custom print preview, an application must connect to the preview signal. The functions
gtkPrintOperationPrintPreviewRenderPage()
,
gtkPrintOperationPreviewEndPreview
and
gtkPrintOperationPreviewIsSelected
are useful
when implementing a print preview.
Printing support was added in GTK+ 2.10.
GtkPrintOperation
GtkPrintOperationPreview
gtkPrintOperation
is the equivalent of gtkPrintOperationNew
.
GtkPrintStatus
initial
preparing
generating-data
sending-data
pending
pending-issue
printing
finished
finished-aborted
GtkPrintOperationAction
action
parameter to gtkPrintOperationRun
determines what action the print operation should perform.
print-dialog
print
preview
export
GtkPrintOperationResult
gtkPrintOperationRun
.
error
apply
cancel
in-progress
GtkPrintError
general
internal-error
nomem
GtkPageSetupDoneFunc(page.setup, data)
gtkPrintRunPageSetupDialogAsync
.
This function will be called when the page setup dialog is dismissed, and
also serves as destroy notify for data
.
page.setup
GtkPageSetup
] the GtkPageSetup
that has beendata
gtkPrintRunPageSetupDialogAsync
.
The (operation, context, user.data)
A typical use for ::begin-print is to use the parameters from the
GtkPrintContext
and paginate the document accordingly, and then
set the number of pages with gtkPrintOperationSetNPages
.
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emittedcontext
GtkPrintContext
] the GtkPrintContext
for the current operationuser.data
The (operation, user.data)
The print dialog owns the returned widget, and its lifetime
isn't controlled by the app. However, the widget is guaranteed
to stay around until the ::custom-widget-apply
signal is emitted on the operation. Then you can read out any
information you need from the widgets.
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emitteduser.data
Returns: [GObject
] A custom widget that gets embedded in the print dialog,
or NULL
The (operation, widget, user.data)
::begin-print
if you added
a custom widget in the gtkPrintOperation
;create-custom-widget handler.
When you get this signal you should read the information from the
custom widgets, as the widgets are not guaraneed to be around at a
later time.
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emittedwidget
GtkWidget
] the custom widget added in create-custom-widgetuser.data
The (operation, result, user.data)
result
gives you information
about what happened during the run. If result
is
GTK_PRINT_OPERATION_RESULT_ERROR
then you can call
gtkPrintOperationGetError
for more information.
If you enabled print status tracking then
gtkPrintOperationIsFinished
may still return FALSE
after ::done
was emitted.
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emittedresult
GtkPrintOperationResult
] the result of the print operationuser.data
The (operation, context, page.nr, user.data)
page.nr
's page onto the cairo context obtained
from context
using gtkPrintContextGetCairoContext
.
draw_page <- (operation, context, page_nr, user_data) { cr <- context$getCairoContext() width <- context$getWidth() cr$rectangle(0, 0, width, HEADER_HEIGHT) cr$setSourceRgb(0.8, 0.8, 0.8) cr$fill() layout <- context$createPangoLayout() desc <- pangoFontDescriptionFromString("sans 14") layout$setFontDescription(desc) layout$setText("some text") layout$setWidth(width) layout$setAlignment(layout, "center") layout_height <- layout$getSize()$height text_height <- layout_height / PANGO_SCALE cr$moveTo(width / 2, (HEADER_HEIGHT - text_height) / 2) pangoCairoShowLayout(cr, layout) }
Use gtkPrintOperationSetUseFullPage
and
gtkPrintOperationSetUnit
before starting the print operation
to set up the transformation of the cairo context according to your
needs.
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emittedcontext
GtkPrintContext
] the GtkPrintContext
for the current operationpage.nr
user.data
The (operation, context, user.data)
::begin-print
handler.
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emittedcontext
GtkPrintContext
] the GtkPrintContext
for the current operationuser.data
The (operation, context, user.data)
::begin-print
signal, but before
the actual rendering starts. It keeps getting emitted until it
returns FALSE
.
The ::paginate signal is intended to be used for paginating the document
in small chunks, to avoid blocking the user interface for a long
time. The signal handler should update the number of pages using
gtkPrintOperationSetNPages
, and return TRUE
if the document
has been completely paginated.
If you don't need to do pagination in chunks, you can simply do it all in the ::begin-print handler, and set the number of pages from there.
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emittedcontext
GtkPrintContext
] the GtkPrintContext
for the current operationuser.data
Returns: [logical] TRUE
if pagination is complete
The (operation, preview, context, parent, user.data)
The default handler for this signal uses an external viewer application to preview.
To implement a custom print preview, an application must return
TRUE
from its handler for this signal. In order to use the
provided context
for the preview implementation, it must be
given a suitable cairo context with gtkPrintContextSetCairoContext
.
The custom preview implementation can use
gtkPrintOperationPreviewIsSelected
and
gtkPrintOperationPreviewRenderPage
to find pages which
are selected for print and render them. The preview must be
finished by calling gtkPrintOperationPreviewEndPreview
(typically in response to the user clicking a close button).
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emittedpreview
GtkPrintOperationPreview
] the GtkPrintPreviewOperation
for the current operationcontext
GtkPrintContext
] the GtkPrintContext
that will be usedparent
GtkWindow
] the GtkWindow
to use as window parent, or NULL
user.data
Returns: [logical] TRUE
if the listener wants to take over control of the preview
The (operation, context, page.nr, setup, user.data)
setup
will be in force only for printing this page.
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emittedcontext
GtkPrintContext
] the GtkPrintContext
for the current operationpage.nr
setup
GtkPageSetup
] the GtkPageSetup
user.data
The (operation, user.data)
GtkPrintStatus
for the phases that are being discriminated.
Use gtkPrintOperationGetStatus
to find out the current
status.
Since 2.10
operation
GtkPrintOperation
] the GtkPrintOperation
on which the signal was emitteduser.data
allow-async
[logical : Read / Write]Determines whether the print operation may run asynchronously or not.
Some systems don't support asynchronous printing, but those that do
will return GTK_PRINT_OPERATION_RESULT_IN_PROGRESS
as the status, and
emit the done signal when the operation is actually done.
The Windows port does not support asynchronous operation
at all (this is unlikely to change). On other platforms, all actions
except for GTK_PRINT_OPERATION_ACTION_EXPORT
support asynchronous
operation.
Default value: FALSE Since 2.10
current-page
[integer : Read / Write]The current page in the document.
If this is set before gtkPrintOperationRun
,
the user will be able to select to print only the current page.
Note that this only makes sense for pre-paginated documents.
Allowed values: >= -1 Default value: -1 Since 2.10
custom-tab-label
[character : Read / Write]Used as the label of the tab containing custom widgets. Note that this property may be ignored on some platforms.
If this is NULL
, GTK+ uses a default label.
Default value: NULL Since 2.10
default-page-setup
[GtkPageSetup
: Read / Write]
The GtkPageSetup
used by default.
This page setup will be used by gtkPrintOperationRun
,
but it can be overridden on a per-page basis by connecting
to the ::request-page-setup
signal.
Since 2.10
export-filename
[character : Read / Write]The name of a file file to generate instead of showing the print dialog. Currently, PDF is the only supported format.
The intended use of this property is for implementing "Export to PDF" actions.
"Print to PDF" support is independent of this and is done by letting the user pick the "Print to PDF" item from the list of printers in the print dialog.
Default value: NULL Since 2.10
job-name
[character : Read / Write]A string used to identify the job (e.g. in monitoring applications like eggcups).
If you don't set a job name, GTK+ picks a default one by numbering successive print jobs.
Default value: "" Since 2.10
n-pages
[integer : Read / Write]The number of pages in the document.
This must be set to a positive number
before the rendering starts. It may be set in a
::begin-print
signal hander.
Note that the page numbers passed to the
::request-page-setup
and
::draw-page
signals are 0-based, i.e. if
the user chooses to print all pages, the last ::draw-page signal
will be for page n.pages
- 1.
Allowed values: >= -1 Default value: -1 Since 2.10
print-settings
[GtkPrintSettings
: Read / Write]
The GtkPrintSettings
used for initializing the dialog.
Setting this property is typically used to re-establish
print settings from a previous print operation, see
gtkPrintOperationRun
.
Since 2.10
show-progress
[logical : Read / Write]Determines whether to show a progress dialog during the print operation.
Default value: FALSE Since 2.10
status
[GtkPrintStatus
: Read]The status of the print operation.
Default value: GTK_PRINT_STATUS_INITIAL Since 2.10
status-string
[character : Read]
A string representation of the status of the print operation.
The string is translated and suitable for displaying the print
status e.g. in a GtkStatusbar
.
See the ::status property for a status value that is suitable for programmatic use.
Default value: "" Since 2.10
track-print-status
[logical : Read / Write]
If TRUE
, the print operation will try to continue report on
the status of the print job in the printer queues and printer.
This can allow your application to show things like "out of paper"
issues, and when the print job actually reaches the printer.
However, this is often implemented using polling, and should
not be enabled unless needed.
Default value: FALSE Since 2.10
unit
[GtkUnit
: Read / Write]
The transformation for the cairo context obtained from
GtkPrintContext
is set up in such a way that distances
are measured in units of unit
.
Default value: GTK_UNIT_PIXEL Since 2.10
use-full-page
[logical : Read / Write]
If TRUE
, the transformation for the cairo context obtained
from GtkPrintContext
puts the origin at the top left corner
of the page (which may not be the top left corner of the sheet,
depending on page orientation and the number of pages per sheet).
Otherwise, the origin is at the top left corner of the imageable
area (i.e. inside the margins).
Default value: FALSE Since 2.10
Derived by RGtkGen from GTK+ documentation
http://developer.gnome.org/doc/API/2.0/gtk/gtk-High-level-Printing-API.html