86
votes

What Python PDF libraries are there?

I need to make some PDF with many grids, and I'm looking for a library that allows to manage pages (multi-page). The library should calculate when the page is ended and then create the next page.

4
Maybe it could be rephrased to ask what libraries are suitable for generating appropriate PDFs for the askers use case. "The best" is too subjective. - Alpaca
With respect to your second "question" (pagebreaks) you might want to use pdflatex. - Tobias Kienzler
There is a nice tutorial, binpress.com/tutorial/manipulating-pdfs-with-python/167 that named some 5 libraries: pdfrw, slate, PDFQuery, PDFMiner, PyPDF2 - WebComer
xhtml2pdf is based on html templates and uses ReportLab. It's quite fast to grab and it answers the OP needs. - Ehvince
There's also rinohtype, which is similar to LaTeX as it focuses on rendering structured documents. (full discloure: I am the author of rinohtype). - Brecht Machiels

4 Answers

34
votes

The two that come to mind are:

33
votes

Reportlab. There is an open source version, and a paid version which adds the Report Markup Language (an alternative method of defining your document).

5
votes

I already have used Reportlab in one project.

3
votes

There is also http://appyframework.org/pod.html which takes a LibreOffice or OpenOffice document as template and can generate pdf, rtf, odt ... To generate pdf it requires a headless OOo on some server. Documentation is concise but relatively complete. http://appyframework.org/podWritingTemplates.html If you need advice, the author is rather helpful.