Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将本地 HTML 转换为 PDF,但 html 文档包含非 ASCII 字符,最终在 PDF 中被破坏。为什么不适pisa用于所有 UTF-8 字符?
pisa
with open('file.html') as m: data = m.read() m.close() pisa.CreatePDF(data, file('final.pdf', 'w'))
知道了。这需要在您生成的内容的顶部:
<meta http-equiv="content-type" content="text/html; charset=utf-8">
对我来说,它有助于使用encoding='utf-8'的编码选项:
pisa.CreatePDF(html.content, dest=pdfFile, encoding='utf-8')