1

tl;dr: Python-PDFkit generates an error when a CSS file is provided during HTML to PDF conversion.

I'm using Python-PDFkit (that uses WkHTMLtoPDF based on Qt) to turn an HTML file into a PDF file. The HTML is generated by Jinja2 and contain base64 images, text and Bootstrap-like custom CSS file. The conversion is correct when no CSS file is provided :

import pdfkit


pdfkit.from_file(file_name + ".html", file_name + ".pdf", options=pdfkit_options)

But when I add CSS files :

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)

Then PDFkit produces a WkHTMLtoPDF error:

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

What's wrong? Any idea? I'm working on a CentOS and Python 3 environment.

Martin Gergov
  • 1,556
  • 4
  • 20
  • 29
Teazane
  • 134
  • 2
  • 11

0 Answers0