[PyQt] QtWebKit to PDF rendering

Dominic Jacobssen dominic.jacobssen at gmail.com
Wed Sep 23 15:04:37 BST 2009


On Wed, Sep 23, 2009 at 1:21 PM, Giovanni Bajo <rasky at develer.com> wrote:
> There's already a complete solution available for this:
> http://code.google.com/p/wkhtmltopdf/
>
> You may want to have a look at the code.

Hi Giovanni; thanks for your reply.

Unfortunately, I've already seen wkhtmltopdf. As I said in my original email:

"""
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.
"""

As an example of this, the patches to Qt include things like a
"usePrintMediaType=true" argument in qwebframe and methods like
printingNewPage().

I was hoping that enough of the webkit internals were exposed to
enable a "poor man's version" to be built that would at least paginate
(possibly suboptimally), and that someone with more Painter-Fu would
be able to point out what I was doing wrong with my coordinate system
such that it wasn't scaling properly.

I modelled my approach on fragmentary examples here:

  http://www.blogs.uni-osnabrueck.de/rotapken/2008/12/03/create-screenshots-of-a-web-page-using-python-and-qtwebkit/
  http://www.blogs.uni-erlangen.de/static/webworking/files/webkit2png.py\
  http://www.insecure.ws/2009/04/02/xserver-less-webpage-screenshot-c

... all of which take the general approach of doing:

    self.page.setViewPortSize ( self.mainFrame.contentsSize() )

Cheers,

D


More information about the PyQt mailing list