This include adds very easy-to-use printing capabilities to EuGTK; most printing tasks require only one or two extra lines of code.
It offers the ability to print documents on physical printers as well as to print them as .pdf or .ps (postscript), and perhaps .svg files, depending upon the hardware and software installed on your pc.
When printing, font size, lines-per-page, and page length must be taken into account. Obviously, the larger the font, the fewer lines will fit on a given page.
By default (on Linux), GtkPrinter.e will print using an Ubuntu Mono 8pt. font and print 62 lines per 8.5x11 inch (na_letter) page or 84 lines on 8.5x14 (na_legal) paper. Other paper sizes and orientations are available from the pop-up printer dialog, and these should also be computed automatically, as long as the font isn't changed. Try test190.
Other fonts may not work so well with the default lines_per_page settings. They often take up more (or less) space, both vertically and horizontally, than the same size Ubuntu Mono font. For these, you must set lines_per_page manually.
Example 1:
printer:font = "Ubuntu mono 10" printer:lines_per_page = 65Example 2:
printer:font = "Purisa 12" printer:lines_per_page = 34
Some options, like the paper size and orientation, can also be changed by selections in the pop-up printer dialogs. When paper size or orientation is changed via the pop-up dialog, the auto_lpp will adjust for those. If you're specifying fonts manually, or auto_lpp is FALSE, you'll have to set these in advance.
Your program can override many other settings exported by GtkPrinter.e, some of the most useful being:
Adding print capability to your program is actually pretty easy. There are two main options:
Often, you can save a lot of typing by simply connecting a call to print_file or print_text to a button, followed by the file name, file handle or text to print as the data item:
constant btn1 = create(GtkButton,"gtk-print",print_file,"~/demos/GtkEngine.e")-- default title will be GtkEngine.e
constant btn2 = create(GtkButton,"gtk-print",print_text,LGPL)
constant btn3 = create(GtkButton,"gtk-print",print_file,fn) -- using a Eu file handle to a previously opened file
See test189 and test190 for various ways to call these functions.
If you call the print routines via a normal function call, you have the option to add a page title to appear in the header.
PrintFile("~/demos/GtkEngine.e") -- default title will be "GtkEngine.e"
PrintFile("License Terms","~/demos/license.txt") -- title will be "License Terms"
See test189 and test190 for various ways to call these functions. PrintText("",LGPL) -- no title
PrintText("Lesser General Public License",LGPL) -- prints "Lesser General Public License" as the title
See test191 to see how to print direct to a .pdf file.
You may wish to override the default page header and/or footer formats.
Headers and footers are printed using text:format(), so you can choose what info shows
and in what order by using square brackets.
For example:
printer:header = "" -- no header
printer:header = "Title: <b>[1]</b> User: [9]\n\n" -- prints page title (bold) and user name
The numbers in the format box or boxes in the header or footer will be replaced with:
If you use custom headers or footers, be sure to declare them after you call
show_all(mainwindow)
. This way, they won't be accessed until after the GTK engine has been fully initialized. Of course, if you print from
a Eu function you have written, you can declare the header and/or footer formats at the start of the function. They won't be set until
the function is called.
The current date display format can be changed by overriding printer:date_format.The format is the same as used in std/datetime.e.
There's a ready-to use progressbar exported by GtkPrinter.e. To use it,
just add it in the appropriate place on your window or dialog:
pack(panel,printer:progress)
The progressbar will be updated automatically. Sometimes it's nice to hide the progressbar until printing begins.
You can construct a custom tab and page which will be added to the print dialog. To do so, you will need to override 3 variables in GtkPrinter.e.