Gtk.PrintOperation
const Gtk = imports.gi.Gtk;
let print_operation = new Gtk.PrintOperation({
allow_async: value,
current_page: value,
custom_tab_label: value,
default_page_setup: value,
embed_page_setup: value,
export_filename: value,
has_selection: value,
job_name: value,
n_pages: value,
print_settings: value,
show_progress: value,
support_selection: value,
track_print_status: value,
unit: value,
use_full_page: value,
});
GtkPrintOperation is the high-level, portable printing API. It looks a bit different than other GTK+ dialogs such as the Gtk.FileChooser, 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 Gtk.new when the user selects to print. Then you set some properties on it, e.g. the page size, any Gtk.PrintSettings from previous print operations, the number of pages, the current page, etc.
Then you start the print operation by calling Gtk.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.PrintOperation, the main one being Gtk.draw-page, which you are supposed to catch and render the page on the provided Gtk.PrintContext using Cairo.
<example> <title>The high-level printing API</title> <programlisting> 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); } </programlisting> </example>
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 Gtk.render_page, Gtk.end_preview and Gtk.is_selected are useful when implementing a print preview.
Hierarchy
-
GObject.Object
- Gtk.PrintOperation
Methods
- Gtk.PrintOperation.prototype.cancel
- Gtk.PrintOperation.prototype.draw_page_finish
- Gtk.PrintOperation.prototype.get_default_page_setup
- Gtk.PrintOperation.prototype.get_embed_page_setup
- Gtk.PrintOperation.prototype.get_error
- Gtk.PrintOperation.prototype.get_has_selection
- Gtk.PrintOperation.prototype.get_n_pages_to_print
- Gtk.PrintOperation.prototype.get_print_settings
- Gtk.PrintOperation.prototype.get_status
- Gtk.PrintOperation.prototype.get_status_string
- Gtk.PrintOperation.prototype.get_support_selection
- Gtk.PrintOperation.prototype.is_finished
- Gtk.PrintOperation.prototype.run
- Gtk.PrintOperation.prototype.set_allow_async
- Gtk.PrintOperation.prototype.set_current_page
- Gtk.PrintOperation.prototype.set_custom_tab_label
- Gtk.PrintOperation.prototype.set_default_page_setup
- Gtk.PrintOperation.prototype.set_defer_drawing
- Gtk.PrintOperation.prototype.set_embed_page_setup
- Gtk.PrintOperation.prototype.set_export_filename
- Gtk.PrintOperation.prototype.set_has_selection
- Gtk.PrintOperation.prototype.set_job_name
- Gtk.PrintOperation.prototype.set_n_pages
- Gtk.PrintOperation.prototype.set_print_settings
- Gtk.PrintOperation.prototype.set_show_progress
- Gtk.PrintOperation.prototype.set_support_selection
- Gtk.PrintOperation.prototype.set_track_print_status
- Gtk.PrintOperation.prototype.set_unit
- Gtk.PrintOperation.prototype.set_use_full_page