我无法使用PyFPDF输出 HTML 消息。当我尝试将 HTML 写入 PDF 文档时,出现错误:
Traceback (most recent call last):
File "/Users/elcid/Projects/so_test/test.py", line 8, in <module>
pdf.write_html("<b>Sample HTML</b>")
File "/Users/elcid/.pyenv/versions/so/lib/python3.9/site-packages/fpdf/html.py", line 400, in write_html
text = h2p.unescape(text) # To deal with HTML entities
AttributeError: 'HTML2FPDF' object has no attribute 'unescape'
违规代码:
from fpdf import FPDF, HTMLMixin
class PDF(FPDF, HTMLMixin):
pass
pdf = PDF()
pdf.add_page()
pdf.write_html("<b>Sample HTML</b>")
pdf.output("html.pdf")
我正在使用 Python 3.9。有什么见解吗?谢谢!