问题描述
在python中使用jinja2和pdfkit库将包含Percian文本的html文件转换为pdf文件时,我遇到了问题。这是一个包含Percian文本的html模板文件:
<!DOCTYPE html>
<html>
<head lang="fa-IR">
<meta charset="UTF-8">
<title></title>
</head>
<body >
<p dir="rtl">سوابق کاری</p>
<ul dir="rtl">
{% for experience in experiences %}
<li><a href="{{ experience.url }}">{{ experience.title }}</a></li>
{% endfor %}
</ul>
</body>
</html>
这是我的python代码:
from jinja2 import Template
from pdfkit import pdfkit
sample_data = [{'url': 'http://www.google.com/','title': 'گوگل'},{'url': 'http://www.yahoo.com/fa/','title': 'یاهو'},{'url': 'http://www.amazon.com/','title': 'آمازون'}]
with open('template.html','r') as template_file:
template_str = template_file.read()
template = Template(template_str)
resume_str = template.render({'experiences': sample_data})
options = {'encoding': "UTF-8",'quiet': ''}
bytes_array = pdfkit.PDFKit(resume_str,'string',options=options).to_pdf()
with open('result.pdf','wb') as output:
output.write(bytes_array)
我收到此错误:
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)