django-wkhtmltopdf on a linux (Webfaction) server
Generating PDF with python is not an easy thing. Here is what I’ve tried:
- xhtml2pdf: the worst. It has a very bad CSS interpreter and it is pretty impossible to make a clean PDF out from a complex html page.
- WeasyPrint: that’s better. It has its own HTML and CSS2 interpreters, and despite some minor issues it is fairly reliable. However it requires some big dependencies, and I eventually had some memory issues on my webserver.
- wkhtmltopdf with its Django wrapper: for now, the best. It makes use of Webkit to render HTML+CSS+JS(!) pages, I don’t think you can do better. However, it requires QT, and this is big. Well, not the “classical” QT, a patched QT (that’s even worse) that allows to run without an X server. This is what I’m using for now in my projects
We’ll see here how to build wkhtmltopdf and a basic django-wkhtmltopdf
usage. These steps has been tested on a Webfaction server (CentOS 6) through SSH.