[英]python pisa utf8 issue
I am trying to convert a local HTML to a PDF, but the html document has non-ASCII characters that end up broken in the PDF. 我正在尝试将本地HTML转换为PDF,但是html文档中的非ASCII字符最终在PDF中损坏。 Why does pisa
not work for all UTF-8 characters? 为什么pisa
不适用于所有UTF-8字符?
with open('file.html') as m:
data = m.read()
m.close()
pisa.CreatePDF(data, file('final.pdf', 'w'))
Got it. 得到它了。 This needs to be at the top of your generated content: 这必须在您生成的内容的顶部:
<meta http-equiv="content-type" content="text/html; charset=utf-8">
对我来说,它有助于使用encoding ='utf-8'的encoding选项:
pisa.CreatePDF(html.content, dest=pdfFile, encoding='utf-8')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.