Is there any Python 3 module to create PDF files?

15,862

Solution 1

The cairo library with the pycairo (not py2cairo, that's for python 2) binding works with python 3.x and can produce PDF output (among others).

Solution 2

There is a new kid on the block which look promising. It supports print css features like page break.

Try weasyprint

Solution 3

In the end I find it difficult to work with pycario/pango, pycairo stil misses some method for png's and PIL is not quite yet supported in python3, also carries a lot of dependencies (the idea of using pycario) so I end up porting a python 2 library to python 3, is not very advanced but gets the jobs done for some basic pdfs, it's called py3fpdf

--- update --

It turn out that p3fpdf didn't get the jobs done n_n'. So to tell the end of the story, I made a preprocessor to apache fop it s called pypfop. I just recently decouple with the full project, It a work in progress specially with documentation, the examples may be illustrative.

Solution 4

You could got the HTML/CSS route and use prince although it's not free software.

If your source is not too complex, you can also try a pure python solution as in http://code.activestate.com/recipes/189858-python-text-to-pdf-converter/

Share:
15,862
cyraxjoe
Author by

cyraxjoe

Software developer, GNU/Linux system administrator and free software enthusiast.

Updated on June 08, 2022

Comments

  • cyraxjoe
    cyraxjoe about 2 years

    I have for some time looking for something to be able to create PDFs and integrate with my current project in Python 3. The usual references are Reportlab or pyPDF. But these two are not yet compatible with Python 3. I do see that since 2010 there has been some discussion about the port in Reportlab, but as of today I can't find any reference to the port.

    Another alternative is to use an intermediate format from Python 3 to be consumed in another program, wrapped with a subprocess call. Relatorio does this. I might consider doing something similar or even generate XHTML/CSS and use xhtml2pdf.