13👍
WeasyPrint author here. The point of using HTML/CSS to generate PDF (vs. using a lower-level PDF library directly.) is to get automatic layout. It lets you specify high-level constraints like h1 { page-break-after: avoid }
and let the layout engine figure it out, rather than specifying the absolute position of everything. The former is much more maintainable when you make changes to your documents.
Some tools like rst2pdf have their own stylesheet syntax, but that’s just a bad way of re-inventing CSS.
But yes, dumping complex stylesheets made for screen might not give great results. It’s better to build the stylesheets with print in mind, or even use completely different stylesheets with @media print
in CSS or <link media="print">
in HTML.
7👍
I think generating a pdf from html with libraries like Pisa or http://weasyprint.org/ is the simplest approach. because it takes care of inserting images, css, barcode (on pisa) … etc
If you want to write the pdf yourself take a look at Reportlab but it will take much longer to implement. In both cases i suggest to always generate the pdf in the background with celery or python-rq for optimization.
4👍
Pisa is known having various issues – especially with long tables. In general one should avoid using PISA. Other options are:
- using Reportlab directly
- z3c.rml (Reportlab template language clone)
- commercial alternatives:
- PrinceXML
- PDFreactor
The general rule when it comes to PDF production: you get what you pay for.
Converters like Pisa or Apache FOP are half-baked solutions that work for simple cases but suck in general.
- How to test django caching?
- Pycharm (Python IDE) doesn't auto complete Django modules
- Django form field grouping
- Django: Create and save a model using JSON data
2👍
You can also use the QT webkit rendering engine to create PDFs from HTML with http://code.google.com/p/wkhtmltopdf/ and django-wkhtmltopdf.
The advantage is that you can write the HTML and CSS as you would normally for WebKit. This works well if you are outputting an existing web page but may be less appropriate if generating PDFs from scratch.
- Passing an object created with SubFactory and LazyAttribute to a RelatedFactory in factory_boy
- Changes made to (static) CSS file not reflecting in Django development server
- Make Django return response as a "different filename"