Has anyone tried html2pdf in django?

Okay, when I am going to create reports with Java, I use iReport projects to design JasperReports templates.

But with python, the alternative is html2pdf - pisa.

It would be great to see an example of this. Any hint would be appreciated.

+2


source to share


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 to application/pdf

    and use a header Content-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


And yes, http://www.xhtml2pdf.com comes with a djangoproject example :)



+3


source


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







All Articles