Python3 html到pdf [英] Python3 html to pdf
问题描述
如何在Python3中将HTML转换为PDF? Xhtml2pdf在Python3中不起作用,出现错误:
how to convert HTML to PDF in Python3? Xhtml2pdf does not work in Python3, got error:
将xhtml2pdf.pisa导入为比萨 追溯(最近一次通话): 文件",第1行,在 在第41行的"/home/hound/test/python/test_env/lib/python3.4/site-packages/xhtml2pdf/init.py"文件中 从xhtml2pdf.util导入REPORTLAB22 文件"/home/hound/test/python/test_env/lib/python3.4/site-packages/xhtml2pdf/util.py",第302行 引发异常,未正确定义框" ^ SyntaxError:语法无效
import xhtml2pdf.pisa as pisa Traceback (most recent call last): File "", line 1, in 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
推荐答案
到目前为止,我发现最好的是weasyprint
.
The best that I found by far is weasyprint
.
从文档:
from weasyprint import HTML
HTML('http://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf')
from weasyprint import HTML
HTML('http://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf')
它真的很容易.节省了我很多时间(在我浪费时间试图让xhtml2pdf和其他人在python 3中工作之后,却失败了.
and it really works that easy. Saved me tons of time (after I wasted time trying to get xhtml2pdf and others to work in python 3 but failed.
这篇关于Python3 html到pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!