First steps on building PDF files from a django app

I’ve been building a web application that operates on information extracted from a storage-engine used by GnuCash. GnuCash 2.6 comes with python-bindings, allowing a developer to rapidly build applications working on data maintained by the application

The main reason I decided to build this application was the way the invoices look and the limited options to change the layout. I really enjoy the functions that are build into GnuCash, so the idea was to build a django app that operates on data extracted from the GnuCash storage engine using python-bindings. The initial thought was to work on the data directly, but the approach changed as Geert Janssens pointed out what I would have to deal with. Django has a way of separating non-modifyable data from data maintained by the application itself, so I feel it worked out great.

This post is to help anybody who’s starting on a pdf export using django, so here are some hints:

  • Use weasyprint. It feels more up-to-date than xhtml2pdf and there are plenty of hints on how to get stuff done.
  • I found knacss to be light. It was easy to use and it worked great on chrome and weasyprint. You’ll have to do some commenting to get weasyprint to process the stylesheet.
  • Use “Save as PDF” from Chrome to make sure you’re focussing on the right thing. It took me too much time to discover knacss @media selector for printing was bothering me. Disabling that section resolved it for me.2014-02-16 16_12_34-KNACSS_css_knacss.css at master · raphaelgoetter_KNACSS

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *