python pisa utf8问题

时间:2012-08-29 19:49:49

标签: python pdf utf-8 pisa

我正在尝试将本地HTML转换为PDF,但html文档中包含非ASCII字符,最终会破坏PDF格式。为什么pisa不适用于所有UTF-8字符?

with open('file.html') as m:
  data = m.read()
  m.close()        
  pisa.CreatePDF(data, file('final.pdf', 'w'))

2 个答案:

答案 0 :(得分:4)

知道了。这需要位于生成内容的顶部:

<meta http-equiv="content-type" content="text/html; charset=utf-8"> 

答案 1 :(得分:0)

对我来说,它有助于在编码=&#39; utf-8&#39; 中使用编码选项:

pisa.CreatePDF(html.content, dest=pdfFile, encoding='utf-8')