Error when clicking the PDF button(Print Format Custom)

Hi there, I’m having an issue with the PDF button on a document. Error log: Traceback (most recent call last):

File “apps/frappe/frappe/utils/pdf.py”, line 38, in get_pdf
filedata = pdfkit.from_string(html, options=options or {}, verbose=True)
File “env/lib/python3.10/site-packages/pdfkit/api.py”, line 75, in from_string
return r.to_pdf(output_path)
File “env/lib/python3.10/site-packages/pdfkit/pdfkit.py”, line 201, in to_pdf
self.handle_error(exit_code, stderr)
File “env/lib/python3.10/site-packages/pdfkit/pdfkit.py”, line 155, in handle_error
raise IOError(‘wkhtmltopdf reported an error:\n’ + stderr)
OSError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: ContentNotFoundError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “apps/frappe/frappe/app.py”, line 66, in application
response = frappe.api.handle()
File “apps/frappe/frappe/api.py”, line 54, in handle
return frappe.handler.handle()
File “apps/frappe/frappe/handler.py”, line 45, in handle
data = execute_cmd(cmd)
File “apps/frappe/frappe/handler.py”, line 83, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “apps/frappe/frappe/init.py”, line 1607, in call
return fn(*args, **newargs)
File “apps/frappe/frappe/utils/print_format.py”, line 129, in download_pdf
pdf_file = frappe.get_print(
File “apps/frappe/frappe/init.py”, line 2040, in get_print
return get_pdf(html, options=pdf_options, output=output)
File “apps/frappe/frappe/utils/pdf.py”, line 46, in get_pdf
frappe.throw(_(“PDF generation failed because of broken image links”))
File “apps/frappe/frappe/init.py”, line 525, in throw
msgprint(
File “apps/frappe/frappe/init.py”, line 493, in msgprint
_raise_exception()
File “apps/frappe/frappe/init.py”, line 442, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.ValidationError: PDF generation failed because of broken image links

The document prints correctly, but an error occurs when trying to download the PDF using the button.

The custom print format does not contain any links or images.

The error log shows the “send_workflow_action_email” error, which indicates the same issue: “frappe.exceptions.ValidationError: PDF generation failed because of broken image links.”

Previously, I encountered the same error while printing the document, which was resolved by removing a field that no longer existed but was still present in the custom print format. However, the error still persists when trying to download the PDF using the button.

Thanks!

This is normally caused by a wkhtmltopdf version problem (reqd = 0.12.6+ with qt patch)

2 Likes

Thank you for your response. It was confirmed that the version is 0.12.6 by running the command ‘wkhtmltopdf --version’.

Do you have the qt patched version?
Also see this post

1 Like

Thanks to the information provided in the referenced post, we were able to successfully resolve the issue. It was discovered that the hostname was missing in the site_config.json file, and now it’s functioning correctly. We greatly appreciate your invaluable assistance!

1 Like

I solved this issue by use
bench --site site-name add-to-hosts

Hey, I am still facing the same issue please help after adding to hosts

after use
bench --site site-name add-to-hosts
use
bench --site site-name clear-cache
bench --site site-name migrate

1 Like