PrintOperation


Object Hierarchy:

Object hierarchy for PrintOperation

Description:

[ CCode ( type_id = "gtk_print_operation_get_type ()" ) ]
public class PrintOperation : Object, PrintOperationPreview

`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 [class@Gtk.PrintUnixDialog].

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

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

The high-level printing API

```c 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 `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 [method@Gtk.PrintOperationPreview.render_page], [method@Gtk.PrintOperationPreview.end_preview] and [method@Gtk.PrintOperationPreview.is_selected] are useful when implementing a print preview.


Namespace: Gtk
Package: gtk4

Content:

Properties:

Creation methods:

Methods:

Signals:

Inherited Members:

All known members inherited from interface Gtk.PrintOperationPreview