views:

481

answers:

3

Ok when im gonna make reports with Java I use iReport for JasperReports Template designs.

But with python the alternative is html2pdf - pisa.

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

+2  A: 

The accounting software we are developing uses pisa to generate pdf reports. The process is like this:

  1. Render a HTML template
  2. Convert the rendered string to pdf. You can directly use the HttpResponse object you will return as output file, or a StringIO object to store the pdf and send its content via HttpResponse.
  3. The mimetype of HttpResponse object should be set to application/pdf and use Content-Disposition header if you want to trigger download instead of displaying in the browser.

Pisa uses some unique CSS properties to specify pdf related formatting (page-size, page-break etc). Their docs provide sufficient examples on this.

Pisa's rendering of HTML/CSS can be quite a bit different from what we usually see in browser. For example, setting border="1" on a <table> will give all cells of the table border, borders are always collapsed (border-collapse css attribute has no effect) etc.

Imran
+2  A: 

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

panchicore
+1  A: 

This is written by me, but answers the exact same questions, so linking it here. http://uswaretech.com/blog/2008/10/generating-pdfs-with-django/

uswaretech