Search code examples
printingmonogtk

What is the best way to print a Gtk.Widget to the printer?


I have a couple of (mostly) text widgets that I would like to render to a printer through a standard "Print..." menu option. One widget is a Mono.TextEditor document, and the other is a Gtk.TextView.

I'm looking for a pretty basic print for now, which might wrap long lines, and add page numbers. Do I need to code all of this myself somehow?

If you have pointers, that would be great, especially if they were in C#.


Solution

  • For line wrap and justification, one can use pango Layout options, as described for Python at pygtk/class-pangolayout or for C at pango/pango-Layout-Objects. See functions pango_layout_set_wrap() and pango_layout_set_justify().

    Also see the example-code routines begin_print, do_page_setup, and do_print in file pygtk-demo/demos/print_editor.py, if you have installed pygtk on your system. (On my system, the full path to directory of Python Gtk demo files currently is /usr/share/doc/pygtk2-2.17.0/examples/pygtk-demo/demos)

    For printer setup dialog, see gtk-High-level-Printing-API for C, or class-gtkprintoperation for Python.