I hope that y'all fine, I'm developing an app in Python that one of its functions is to generate a PDF file, but when I try to do it, it raise this exception:
File "D:\Projects\CORE\venv\Lib\site-packages\pdfkit\pdfkit.py", line 158, in handle_error
raise IOError("wkhtmltopdf exited with non-zero code {0}. error:\n{1}".format(exit_code, error_msg))
OSError: wkhtmltopdf exited with non-zero code 1. error:
QPainter::begin(): Returned false
Exit with code 1, due to unknown error.
I'll share you my code:
path_template = os.path.join(settings.BASE_DIR, 'administration\extras')
template_loader =jinja2.FileSystemLoader(path_template)
env = jinja2.Environment(loader=template_loader)
template = env.get_template('template.html')
html = template.render({
'fecha_sesion': fecha_sesion
})
options = {
'page-size': 'Letter',
'margin-top': '0.05in',
'margin-right': '0.05in',
'margin-bottom': '0.05in',
'margin-left': '0.05in',
'encoding': 'UTF-8'
}
config = pdfkit.configuration(wkhtmltopdf='C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe') # <---- El ERROR ahora está acá
ruta_salida = 'D:\Projects\CORE\administration\extras\pdftest.pdf'
pdfkit.from_string(html, ruta_salida, options=options, configuration=config)
I've been using the libraries jinja2 and pdfkit apart to wkhtmltopdf and this one seem to be the problem, I added to the Path in the environment variables the route of wkhtmltopdf.