Python3 html to pdf

How to convert HTML to PDF in Python3? Xhtml2pdf does not work in Python3, got an error:

import xhtml2pdf.pisa as Pisa Traceback (last last call): File ", line 1, to File" / home / hound / test / python / test _env / lib / python3.4 / site-packages / xhtml2pdf / init .py " , line 41, in from xhtml2pdf.util import REPORTLAB22 File "/ home / hound / test / python / test _env / lib / python3.4 / site-packages / xhtml2pdf / util.py", line 302 raise Exception, "box not defined right way "^ SyntaxError: invalid syntax

+3
source share
2 answers

I had the same error. Apparently, at the moment, xhtml2pdf supports Python3 only in its preliminary version - 0.2b1 (for more details see https://pypi.python.org/pypi/xhtml2pdf ). Ive solved the problem by uninstalling the previous version of xhtml2pdf and installing the preliminary version

pip install --pre xhtml2pdf 
+3
source

The best I have found is weasyprint .

From the documentation :

from weasyprint import HTML HTML('http://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf')

and it really is that simple. I saved a lot of time (after I took the time to get xhtml2pdf and others to work on python 3, but failed.

+1
source

All Articles