I want to creat a pdf file with django. But I use python 3. Is there already a libary supportign python3? I found reportlab, pisa, html2py... but I think none support python 3. I hope something like html2py is available.
2 Answers
EDIT: I just came across Django Easy PDF which is Python 3 compatible and may be more useful:
https://github.com/nigma/django-easy-pdf
Note, however, that as of writing this xhtml2pdf which is a dependency of Django Easy PDF only supports Python 3 if you install the latest beta version with:
pip install --pre xhtml2pdf
WeasyPrint is Python 3 compatible:
It's a great library and is easy enough to integrate with Django. Here's a blog post with some suggestions:
-
The problem with weasyprint is embedding fonts. The server must have them installed and most hosts won't let you. I temporarily switched back to python 2.7 and reportlab due to this issue– AlvaroJan 23, 2014 at 15:55
-
Good point. I still like WeasyPrint but just found 'Django Easy PDF' (see edit above) which looks like a good alternative.– keybitsJan 25, 2014 at 18:36
-
6django-easy-pdf depends on xhtml2pdf which is not compatible with python 3 Jul 5, 2014 at 12:00
-
-
1xhtml2pdf added beta support for Python 3. For now you have to install it with
pip install --pre xhtml2pdf
. I updated the answer. Mar 29, 2017 at 15:05
I would rather go for a stack described here using:
wkhtmltopdf
(obtained via apt-get) (info: https://wkhtmltopdf.org/)pip install pdfkit
(info: https://pypi.python.org/pypi/pdfkit)