[PyQt] QtWebKit to PDF rendering

Dominic Jacobssen dominic.jacobssen at gmail.com
Wed Sep 23 06:47:15 BST 2009

Hi all.

I'm a newbie to Qt (but not to Python), and I wanted to ask for "next
step" guidance.

I want to generate PDF reports by pointing a HTML-to-PDF renderer at a
server that spits out well-formed XHTML with inline SVG. I know that
that's a can of worms right there, but I've managed to get a simple
server up and running using the combination of CherryPy + Genshi +
PyChart, and firefox renders it, so that seemed promising.

I know about the "flying saucer" renderer (aka "xhtmlrenderer"), but
that's Java and even though I did manage to use it under Jython) I'd
prefer something more "natively python" (not that Qt is natively
Python, but you get my drift). I have also seen wkhtmltopdf, but it
seems that 60% of the source code was ifdef'd in conjunction with a
heavily patched QtWebKit, so it wasn't very easy to follow through the
flow of source to work out how it worked.

After a couple of hours of hacking I came up with the attached
(pointing to a public website, not an internal server, of course).

This kind of works, but renders the top-left hand corner of the
website onto the page, and I can't for the life of me see any hooks
for controlling pagination. I'm expecting some kind of "progress
callback" interface, a bit like the loadProgress(int) signal, that
gets called every time it starts to render a div above which nothing
else will be rendered.

Or something like that; sorry it's a bit vague, because I don't know
the capabilities of QtWebKit. It's possible that it knows all about
CSS print media and will just do the right thing :-)

Anyway, I've attached my efforts, and I'd greatly appreciate any
guidance or prodding in the right direction.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: WebKitPDF.py
Type: text/x-python
Size: 1815 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090923/e641d5a5/WebKitPDF.py

More information about the PyQt mailing list