gtk.print_operation

Module for [PrintOperation] class

Types 3

[gtk.print_operation.PrintOperation] is the high-level, portable printing API.

It looks a bit different than other GTK dialogs such as the [gtk.file_chooser.FileChooser], since some platforms don’t expose enough infrastructure to implement a good print dialog. On such platforms, [gtk.print_operation.PrintOperation] uses the native print dialog. On platforms which do not provide a native print dialog, GTK uses its own, see [gtk.print_unix_dialog.PrintUnixDialog].

The typical way to use the high-level printing API is to create a [gtk.print_operation.PrintOperation] object with [gtk.print_operation.PrintOperation.new_] when the user selects to print. Then you set some properties on it, e.g. the page size, any [gtk.print_settings.PrintSettings] from previous print operations, the number of pages, the current page, etc.

Then you start the print operation by calling [gtk.print_operation.PrintOperation.run]. 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 [gtk.print_operation.PrintOperation], the main one being signal@Gtk.PrintOperation::draw-page, which you are supposed to handle and render the page on the provided [gtk.print_context.PrintContext] using Cairo.

The high-level printing API

static GtkPrintSettings *settings = NULL;

static void
do_print (void)
{
 GtkPrintOperation *print;
 GtkPrintOperationResult res;

 print = gtk_print_operation_new ();

 if (settings != NULL)
   gtk_print_operation_set_print_settings (print, settings);

 g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), NULL);
 g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL);

 res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                GTK_WINDOW (main_window), NULL);

 if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
   {
     if (settings != NULL)
       g_object_unref (settings);
     settings = g_object_ref (gtk_print_operation_get_print_settings (print));
   }

 g_object_unref (print);
}

By default [gtk.print_operation.PrintOperation] uses an external application to do print preview. To implement a custom print preview, an application must connect to the preview signal. The functions [gtk.print_operation_preview.PrintOperationPreview.renderPage], [gtk.print_operation_preview.PrintOperationPreview.endPreview] and [gtk.print_operation_preview.PrintOperationPreview.isSelected] are useful when implementing a print preview.

Methods
GType _gType() @property
PrintOperation self()Returns `this`, for use in `with` statements.
PrintOperationGidBuilder builder()Get builder for [gtk.print_operation.PrintOperation] Returns: New builder object
bool allowAsync() @propertyGet `allowAsync` property. Returns: Determines whether the print operation may run asynchronously or not.
void allowAsync(bool propval) @propertySet `allowAsync` property. Params: propval = Determines whether the print operation may run asynchronously or not.
int currentPage() @propertyGet `currentPage` property. Returns: The current page in the document.
void currentPage(int propval) @propertySet `currentPage` property. Params: propval = The current page in the document.
string customTabLabel() @propertyGet `customTabLabel` property. Returns: Used as the label of the tab containing custom widgets.
void customTabLabel(string propval) @propertySet `customTabLabel` property. Params: propval = Used as the label of the tab containing custom widgets.
gtk.page_setup.PageSetup defaultPageSetup() @propertyGet `defaultPageSetup` property. Returns: The [gtk.page_setup.PageSetup] used by default.
void defaultPageSetup(gtk.page_setup.PageSetup propval) @propertySet `defaultPageSetup` property. Params: propval = The [gtk.page_setup.PageSetup] used by default.
bool embedPageSetup() @propertyGet `embedPageSetup` property. Returns: If true, page size combo box and orientation combo box are embedded into page setup page.
void embedPageSetup(bool propval) @propertySet `embedPageSetup` property. Params: propval = If true, page size combo box and orientation combo box are embedded into page setup page.
string exportFilename() @propertyGet `exportFilename` property. Returns: The name of a file to generate instead of showing the print dialog.
void exportFilename(string propval) @propertySet `exportFilename` property. Params: propval = The name of a file to generate instead of showing the print dialog.
bool hasSelection() @propertyGet `hasSelection` property. Returns: Determines whether there is a selection in your application.
void hasSelection(bool propval) @propertySet `hasSelection` property. Params: propval = Determines whether there is a selection in your application.
string jobName() @propertyGet `jobName` property. Returns: A string used to identify the job (e.g. in monitoring applications like eggcups).
void jobName(string propval) @propertySet `jobName` property. Params: propval = A string used to identify the job (e.g. in monitoring applications like eggcups).
int nPages() @propertyGet `nPages` property. Returns: The number of pages in the document.
void nPages(int propval) @propertySet `nPages` property. Params: propval = The number of pages in the document.
int nPagesToPrint() @propertyGet `nPagesToPrint` property. Returns: The number of pages that will be printed.
gtk.print_settings.PrintSettings printSettings() @propertyGet `printSettings` property. Returns: The [gtk.print_settings.PrintSettings] used for initializing the dialog.
void printSettings(gtk.print_settings.PrintSettings propval) @propertySet `printSettings` property. Params: propval = The [gtk.print_settings.PrintSettings] used for initializing the dialog.
bool showProgress() @propertyGet `showProgress` property. Returns: Determines whether to show a progress dialog during the print operation.
void showProgress(bool propval) @propertySet `showProgress` property. Params: propval = Determines whether to show a progress dialog during the print operation.
gtk.types.PrintStatus status() @propertyGet `status` property. Returns: The status of the print operation.
string statusString() @propertyGet `statusString` property. Returns: A string representation of the status of the print operation.
bool supportSelection() @propertyGet `supportSelection` property. Returns: If true, the print operation will support print of selection.
void supportSelection(bool propval) @propertySet `supportSelection` property. Params: propval = If true, the print operation will support print of selection.
bool trackPrintStatus() @propertyGet `trackPrintStatus` property. Returns: If true, the print operation will try to continue report on the status of the print job in the printer queues and printer.
void trackPrintStatus(bool propval) @propertySet `trackPrintStatus` property. Params: propval = If true, the print operation will try to continue report on the status of the print job in the printer queues and printer.
gtk.types.Unit unit() @propertyGet `unit` property. Returns: The transformation for the cairo context obtained from [gtk.print_context.PrintContext] is set up in such a way that distances are measured in units of @unit.
void unit(gtk.types.Unit propval) @propertySet `unit` property. Params: propval = The transformation for the cairo context obtained from [gtk.print_context.PrintContext] is set up in such a way that distances are measured in units of @unit.
bool useFullPage() @propertyGet `useFullPage` property. Returns: If true, the transformation for the cairo context obtained from [gtk.print_context.PrintContext] puts the origin at the top left corner of the page.
void useFullPage(bool propval) @propertySet `useFullPage` property. Params: propval = If true, the transformation for the cairo context obtained from [gtk.print_context.PrintContext] puts the origin at the top left corner of the page.
void cancel()Cancels a running print operation.
void drawPageFinish()Signal that drawing of particular page is complete.
gtk.page_setup.PageSetup getDefaultPageSetup()Returns the default page setup. Returns: the default page setup
bool getEmbedPageSetup()Gets whether page setup selection combos are embedded Returns: whether page setup selection combos are embedded
void getError()Call this when the result of a print operation is [gtk.types.PrintOperationResult.Error].
bool getHasSelection()Gets whether there is a selection. Returns: whether there is a selection
int getNPagesToPrint()Returns the number of pages that will be printed.
gtk.print_settings.PrintSettings getPrintSettings()Returns the current print settings.
gtk.types.PrintStatus getStatus()Returns the status of the print operation.
string getStatusString()Returns a string representation of the status of the print operation.
bool getSupportSelection()Gets whether the application supports print of selection Returns: whether the application supports print of selection
bool isFinished()A convenience function to find out if the print operation is finished.
void setAllowAsync(bool allowAsync)Sets whether [gtk.print_operation.PrintOperation.run] may return before the print operation is completed.
void setCurrentPage(int currentPage)Sets the current page.
void setCustomTabLabel(string label = null)Sets the label for the tab holding custom widgets.
void setDefaultPageSetup(gtk.page_setup.PageSetup defaultPageSetup = null)Makes defaultpagesetup the default page setup for op.
void setDeferDrawing()Sets up the [gtk.printoperation.PrintOperation] to wait for calling of [methodGtk.PrintOperation.drawpage_finish from application.
void setEmbedPageSetup(bool embed)Embed page size combo box and orientation combo box into page setup page.
void setExportFilename(string filename)Sets up the [gtk.print_operation.PrintOperation] to generate a file instead of showing the print dialog.
void setHasSelection(bool hasSelection)Sets whether there is a selection to print.
void setJobName(string jobName)Sets the name of the print job.
void setNPages(int nPages)Sets the number of pages in the document.
void setPrintSettings(gtk.print_settings.PrintSettings printSettings = null)Sets the print settings for op.
void setShowProgress(bool showProgress)If show_progress is true, the print operation will show a progress dialog during the print operation.
void setSupportSelection(bool supportSelection)Sets whether selection is supported by [gtk.print_operation.PrintOperation].
void setTrackPrintStatus(bool trackStatus)If track_status is true, the print operation will try to continue report on the status of the print job in the printer queues and printer.
void setUnit(gtk.types.Unit unit)Sets up the transformation for the cairo context obtained from [gtk.print_context.PrintContext] in such a way that distances are measured in units of unit.
void setUseFullPage(bool fullPage)If fullpage is true, the transformation for the cairo context obtained from [gtk.printcontext.PrintContext] puts the origin at the top left corner of the page.
gulong connectBeginPrint(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 3)Connect to `BeginPrint` signal.
gulong connectCreateCustomWidget(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T : gobject.object.ObjectWrap) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 2)Connect to `CreateCustomWidget` signal.
gulong connectCustomWidgetApply(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.widget.Widget))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 3)Connect to `CustomWidgetApply` signal.
gulong connectDone(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.types.PrintOperationResult))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 3)Connect to `Done` signal.
gulong connectDrawPage(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == int))) && (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 4)Connect to `DrawPage` signal.
gulong connectEndPrint(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 3)Connect to `EndPrint` signal.
gulong connectPaginate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == bool) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 3)Connect to `Paginate` signal.
gulong connectPreview(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == bool) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_operation_preview.PrintOperationPreview))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.print_context.PrintContext))) && (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.window.Window))) && (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 5)Connect to `Preview` signal.
gulong connectRequestPageSetup(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_context.PrintContext))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == int))) && (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.page_setup.PageSetup))) && (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 5)Connect to `RequestPageSetup` signal.
gulong connectStatusChanged(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 2)Connect to `StatusChanged` signal.
gulong connectUpdateCustomWidget(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.widget.Widget))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.page_setup.PageSetup))) && (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.print_settings.PrintSettings))) && (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] : gtk.print_operation.PrintOperation))) && Parameters!T.length < 5)Connect to `UpdateCustomWidget` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new [gtk.printoperation.PrintOperation]. Returns: a new [gtk.printoperation.PrintOperation]
Methods
T allowAsync(bool propval)Set `allowAsync` property. Params: propval = Determines whether the print operation may run asynchronously or not.
T currentPage(int propval)Set `currentPage` property. Params: propval = The current page in the document.
T customTabLabel(string propval)Set `customTabLabel` property. Params: propval = Used as the label of the tab containing custom widgets.
T defaultPageSetup(gtk.page_setup.PageSetup propval)Set `defaultPageSetup` property. Params: propval = The [gtk.page_setup.PageSetup] used by default.
T embedPageSetup(bool propval)Set `embedPageSetup` property. Params: propval = If true, page size combo box and orientation combo box are embedded into page setup page. Returns: Builder instance for fluent chaining
T exportFilename(string propval)Set `exportFilename` property. Params: propval = The name of a file to generate instead of showing the print dialog.
T hasSelection(bool propval)Set `hasSelection` property. Params: propval = Determines whether there is a selection in your application.
T jobName(string propval)Set `jobName` property. Params: propval = A string used to identify the job (e.g. in monitoring applications like eggcups).
T nPages(int propval)Set `nPages` property. Params: propval = The number of pages in the document.
T printSettings(gtk.print_settings.PrintSettings propval)Set `printSettings` property. Params: propval = The [gtk.print_settings.PrintSettings] used for initializing the dialog.
T showProgress(bool propval)Set `showProgress` property. Params: propval = Determines whether to show a progress dialog during the print operation. Returns: Builder instance for fluent chaining
T supportSelection(bool propval)Set `supportSelection` property. Params: propval = If true, the print operation will support print of selection.
T trackPrintStatus(bool propval)Set `trackPrintStatus` property. Params: propval = If true, the print operation will try to continue report on the status of the print job in the printer queues and printer.
T unit(gtk.types.Unit propval)Set `unit` property. Params: propval = The transformation for the cairo context obtained from [gtk.print_context.PrintContext] is set up in such a way that distances are measured in units of @unit....
T useFullPage(bool propval)Set `useFullPage` property. Params: propval = If true, the transformation for the cairo context obtained from [gtk.print_context.PrintContext] puts the origin at the top left corner of the page.

Fluent builder for [gtk.print_operation.PrintOperation]