Placing graphics & text on printed page - jan06call.jpg (0/1)

Paul Boddie paul at boddie.org.uk
Fri Jan 13 02:18:16 CET 2006


Steve Holden wrote:
> Michael Galvin wrote:
> > To see an example of what I am trying to accomplish, look at this page
> > on my personal website:
> >
> > http://mysite.verizon.net/michaelgalvin/jan06call.html
> >
> > I now realize my attachement could not be posted on this usenet group.
> >
> I suspect your best option would be to use ReportLab's open source
> package (www.reportlab.org) to generate PDF files.

One alternative, although I'm not convinced that it is actively
maintained any more, is the Piddle/Sping library [1]. As mentioned
elsewhere, the Cairo bindings would provide a similar developer
experience to that, and Cairo is increasingly fashionable.

> You may, however, be able to get at the Windows device context through
> wxPython (www.wxpython.org): if you download the demonstration you'll
> see that on Windows they do send fairly arbitrary graphics to the
> Windows printer queue.

PyQt [2] seems to support printing fairly conveniently. Consider this
very simple example:

from qt import *
import sys
qapp = QApplication(sys.argv)
printer = QPrinter(QPrinter.PrinterResolution)
printer.setPageSize(printer.A4)
printer.setOutputToFile(1)
printer.setOutputFileName("qtprint.ps")
painter = QPainter(printer)
painter.drawText(painter.window(), painter.AlignCenter, "Hello")
painter.end()

I haven't used printing in Qt [3] before, so apologies must go out if
I've made fundamental mistakes in the above code which did, admittedly,
produce output that resembled my expectations. Another route might be
to use a Tkinter canvas - at least in times of old, such canvases were
able to dump their contents as PostScript.

Paul

[1] http://piddle.sourceforge.net/
[2] http://www.riverbankcomputing.co.uk/pyqt/index.php
[3] http://doc.trolltech.com/3.3/graphics.html




More information about the Python-list mailing list