pure python solution to convert well formed XHTML to PDF

159 views
Skip to first unread message

Richard

unread,
Oct 21, 2009, 8:11:06 PM10/21/09
to web2py-users
hello,

I am after a pure Python solution (for the GAE) to convert web pages
to PDF.

I had a look at reportlab (which was recommended in a previous
thread), but the documentation focuses on generating PDFs from
scratch, rather than converting from an existing webpage. (My user
case is I want to let users download a PDF render of my report page,
and I plan to update this report webpage so I don't want to maintain 2
versions of it.)

I have control over the webpages I want to render so I can ensure they
are well formed XHTML.
Do you know of a pure Python solution to convert XHTML to PDF?

thanks,
Richard

mdipierro

unread,
Oct 21, 2009, 8:23:56 PM10/21/09
to web2py-users
reportlab is pure python and it include platypus which has document
creation API very similar to XML. You can write a mapper and I would
be suprised if somebody has not already made one.

villas

unread,
Oct 21, 2009, 8:53:27 PM10/21/09
to web2py-users
Just a simple non-python idea, which can easily be ignored if not
helpful :-)
If your users are downloading the PDF and saving them in an
unstructured way, you could ask them to simply print to PDF and save
it themselves. There are several free PDF printer drivers and we have
used this easy solution very effectively internally. I just
circulated a few instructions and our users got on with it -- saved me
a headache!

Richard

unread,
Oct 21, 2009, 9:25:43 PM10/21/09
to web2py-users
yeah I considered it, but it doesn't work with our situation.
Thanks though.

Richard

unread,
Oct 21, 2009, 9:42:36 PM10/21/09
to web2py-users
Is reportlab really pure Python? According to the installation
documents it relies on freetype2 and PIL.
Has anyone got it working on GAE?

mdipierro

unread,
Oct 21, 2009, 10:20:06 PM10/21/09
to web2py-users
It only relies on PIL you need to import images into documents.
It has some optional c modules for speed buth works without those.

Richard

unread,
Oct 22, 2009, 12:34:59 AM10/22/09
to web2py-users
ah OK.

Another library that was mentioned in an earlier thread was Pisa:
http://www.xhtml2pdf.com/

"pisa is a html2pdf converter using the ReportLab Toolkit, the
HTML5lib and pyPdf. It supports HTML 5 and CSS 2.1 (and some of CSS
3). It is completely written in pure Python so it is platform
independent. The main benefit of this tool that a user with Web skills
like HTML and CSS is able to generate PDF templates very quickly
without learning new technologies. Easy integration into Python
frameworks like CherryPy, KID Templating, TurboGears, Django, Zope,
Plone, Google AppEngine (GAE) etc."

Sounds like just what I am after.
Reply all
Reply to author
Forward
0 new messages