2024-09-29 19:19:43 发布
网友
我正在努力使用python3.5.2、pythonpdfkit和wkhtmltox-0.12.2生成一个包含非ascii字符的简单PDF。在
这是我能写的最简单的例子:
import pdfkit html_content = u'<p>ö</p>' pdfkit.from_string(html_content, 'out.pdf')
输出文档如下所示:
pdfkit项目中存在相关问题https://github.com/devongovett/pdfkit/issues/470 这说明
"You need to use an embedded font. The built-in fonts have a limited character set available."
这个问题的答案How to: output Euro symbol in pdfkit for nodejs给出了一个如何做的线索。在
我发现我只需要在HTML代码中添加一个具有charset属性的meta标记:
import pdfkit html_content = """ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p>€</p> <p>áéíóúñö</p> <body> </html> """ pdfkit.from_string(html_content, 'out.pdf')
事实上,我花了相当长的时间遵循错误的解决方案,就像这里建议的那样。如果有人感兴趣,我写了一篇短篇小说on my blog。抱歉,垃圾邮件:)
pdfkit项目中存在相关问题https://github.com/devongovett/pdfkit/issues/470 这说明
这个问题的答案How to: output Euro symbol in pdfkit for nodejs给出了一个如何做的线索。在
我发现我只需要在HTML代码中添加一个具有charset属性的meta标记:
事实上,我花了相当长的时间遵循错误的解决方案,就像这里建议的那样。如果有人感兴趣,我写了一篇短篇小说on my blog。抱歉,垃圾邮件:)
相关问题 更多 >
编程相关推荐