我正在使用Python-PDFkit(使用基于Qt的WkHTMLtoPDF)将HTML文件转换为PDF文件。 HTML由Jinja2生成,并包含base64图像,文本和类似Bootstrap的自定义CSS文件。如果没有提供CSS文件,则转换是正确的:
pdfkit.from_file(file_name + ".html", file_name + ".pdf", options=pdfkit_options)
但是当我有CSS文件时:
css_files = ["boosted-4.2.2-dist/css/Helvetica.css","boosted-4.2.2-dist/css/Icons.css", "boosted-4.2.2-dist/css/boosted.css"]
pdfkit.from_file(file_name + ".html", file_name + ".pdf", options=pdfkit_options, css=css_files)
然后PDFkit产生WkHTMLtoPDF错误:
Traceback (most recent call last):
File "App.py", line 77, in <module>
report_app.get_reports(client)
File "App.py", line 69, in get_reports
self.get_client_server_report(client[0], server[0])
File "App.py", line 59, in get_client_server_report
pdfkit.from_file(file_name + ".html", file_name + ".pdf", options=pdfkit_options, css=css_files)
File "/data/dev/project/ENV/lib/python3.6/site-packages/pdfkit/api.py", line 49, in from_file
return r.to_pdf(output_path)
File "/data/dev/project/ENV/lib/python3.6/site-packages/pdfkit/pdfkit.py", line 159, in to_pdf
raise IOError("wkhtmltopdf exited with non-zero code {0}. error:\n{1}".format(exit_code, stderr))
OSError: wkhtmltopdf exited with non-zero code -8. error:
load glyph failed err=24 face=0x40727c0, glyph=0
QFontEngine: Glyph neither outline nor bitmap format=0
load glyph failed err=24 face=0x40727c0, glyph=3
QFontEngine: Glyph neither outline nor bitmap format=0
怎么了?任何想法?我正在CentOS和Python 3环境中工作。