Has anyone tried html2pdf in django?
3 answers
The accounting software we develop uses pisa to generate pdf reports. The process looks like this:
- Show HTML Template
- Convert the converted string to pdf. You can use the HttpResponse object directly, which you will return as an output file, or an object
StringIO
to store the PDF file and send its content via HttpResponse. - An object mimetic
HttpResponse
must be set toapplication/pdf
and use a headerContent-Disposition
if you want to trigger the download instead of being displayed in the browser.
Pisa uses some unique CSS properties to indicate PDF-related formatting (page size, page break, etc.). Their papers provide ample examples.
Pisa HTML / CSS rendering may be slightly different from what we usually see in the browser. For example, setting border="1"
to <table>
will give all cells a table border, borders are always collapsed (the border-collapse css attribute has no effect), etc.
+4
source to share
This is written by me but answers the same questions, so linking it here. http://uswaretech.com/blog/2008/10/generating-pdfs-with-django/
+1
source to share