PDF generation not working on some sites but fine on others for custom print templates

I have a deployed server running of ERPNext V13 Production. This server has multiple sites and I have made a custom print format for Sales Invoice that I am using on all of them. For some sites, the PDF is generating without any issues, but, on other sites, it gives me this error.

Traceback (most recent call last):
  File "/home/bench/frappe-bench/apps/frappe/frappe/app.py", line 68, in application
    response = frappe.api.handle()
  File "/home/bench/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "/home/bench/frappe-bench/apps/frappe/frappe/handler.py", line 31, in handle
    data = execute_cmd(cmd)
  File "/home/bench/frappe-bench/apps/frappe/frappe/handler.py", line 67, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/bench/frappe-bench/apps/frappe/frappe/__init__.py", line 1198, in call
    return fn(*args, **newargs)
  File "/home/bench/frappe-bench/apps/frappe/frappe/utils/print_format.py", line 92, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/bench/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 40, in get_pdf
    filedata = pdfkit.from_string(html, False, options=options or {})
  File "/home/bench/frappe-bench/env/lib/python3.8/site-packages/pdfkit/api.py", line 72, in from_string
    return r.to_pdf(output_path)
  File "/home/bench/frappe-bench/env/lib/python3.8/site-packages/pdfkit/pdfkit.py", line 156, in to_pdf
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
OSError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: ProtocolUnknownError

I have checked site_config.json for all sites and it appears to be the same. How can I resolve this issue?

Further information:

  • ERPNext: 13.11.0
  • Frappe: 13.11.0
  • bench: 5.0.0-dev
  • Python: 3.8.10
  • wkhtmltopdf: 0.12.5 (with patched qt)
  • Node: 12.22.6
  • yarn: 1.22.11

what about printing a white page with pdf ? does it work ?

White page PDF is generating properly.
It is also generating for the standard (pre-defined ERPNext) templates.
The custom one that I made is working on some sites but not others. Its print preview shows perfectly fine, but PDF gives the mentioned error.

I have resolved the issue.
In print templates, I was using bootstrap grid for formatting, which works fine for regular printing but causes issues with PDF.

I was using this:

<div class="grid-container print-heading" style="border: none;">
    <div class="grid-item bordered">
    <div class="grid-item center text-bold bordered">
        <h2>  My Heading </h2>
    <div class="grid-item right bordered">
        <img src="img_path" style="width:100px; height:80px;" />

Removing this grid container resolved the issue.

1 Like