Gtk2::Ex::PrintDialog(3) a simple, pure Perl dialog for printing PostScript data in GTK+ applications.


use Gtk2::Ex::PrintDialog;
my $dialog = Gtk2::Ex::PrintDialog->new; # a new dialog
$dialog->set_data($postscript_data); # supply some postscript data
$dialog->set_filename($postscript_file); # get postscript from a file
$dialog->run; # show the dialog to the user


This module implements a dialog widget that can be used to print PostScript data. It is intended to be a lightweight and pure-perl alternative to the Gnome2::Print libraries.

This module uses a simple system of operating-system specific backends that are used to do the job of printing. Currently, only a generic Linux/Unix backend (implemented using Net::CUPS) is available, more will be added in the future.

The dialog itself is intended to comply with the GNOME Human Interface Guidelines (HIG). It allows the user to print to any printer installed on the system, or to an external command such as "lpr", or to print a PostScript or PDF file.

This module is UNSTABLE, the behaviour and API of its components may change in the future.




        my $dialog = Gtk2::Ex::PrintDialog->new;

Returns an instance of "Gtk2::Ex::PrintDialog". These dialogs are subclasse of "Gtk2::Dialog" so all corresponding methods, signals and properties from that class are also available.

The dialog will handle user actions itself so you will probably not need to connect to any signals.


This tells the dialog to use the PostScript data in $data. This might be PostScript data you create yourself, or from another application. This data can subsequently retrieved using "get_data()".


This tells the dialog to use the PostScript data in $file. The file name can be subsequently retrieved using "get_filename()". The contents of the file are read into memory when "set_filename()" is called, so any subequent calls to "get_data()" will return the contents of $file.


If the "Locale::gettext" module is available on the system, and your application uses it, all the strings used in the dialog will be automagically translated, as long as these default values are translated in your .mo files.


Backends are Perl modules with names of the form


See perlvar for details of the $^O variable. The module must have the following methods:

"$backend = Gtk2::Ex::PrintDialog::$^O->new"
The constructor.
Returns an array of printer names.
"$backend->print_file($printer, $file)"
Prints the contents of $file to the printer named $file
Returns the path to the default print command, if applicable (eg '"lpr"')
Returns a true value if PDF printing is supported, "undef" otherwise.
"$backend->print_to_pdf($data, $file)"
Prints the PostScript data in $data to the PDF file named $file.

Consult Gtk2::Ex::PrintDialog::Unix for an example. Please note that this interface may change in the future.


Locale::gettext (recommended)
Net::CUPS (for the Unix/Linux backend)
Ghostscript, for the "ps2pdf" command (recommended)


Implement a "Print Preview" function, maybe using Poppler.
More backends.


Gavin Brown (gavin dot brown at uk dot com)


(c) 2005 Gavin Brown. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.