Error generating PDF

While sending an email with document, getting pdf error. Any suggestion.

Sunil

Did you get any error traceback?

No traceback, getting only error as shared in post.

Sunil

Is wkhtmltopdf installed?

Yes, wkhtmltopdf is installed. And pdf was getting generated earlier.
Environment:

  • Debian wizzy
  • Google cloud

Sunil

i was experiencing the same error. pdf generation fails then sends it as html.

here is the solution

solved it with:

bench set-url-root {sitename} http://{hostname_that_resolves_the_site}

Example

bench set-url-root site1.local https://my.site.com

i found it here https://discuss.frappe.io/t/pdf-generation-error/3401/4?u=admin

2 Likes

Again im experiencing pdf generating error. also the pdf cannot be downloaded

  Traceback (innermost last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 54, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 43, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 66, in handle
    execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 89, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 532, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/templates/pages/print.py", line 94, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 29, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pdfkit/api.py", line 68, in from_string
    return r.to_pdf(output_path)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pdfkit/pdfkit.py", line 116, in to_pdf
    raise IOError('wkhtmltopdf reported an error:\n' + stderr.decode('utf-8'))
 IOError: wkhtmltopdf reported an error:
Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[==========>                                                 ] 17%
[========================>                                   ] 41%
[============================>                               ] 47%
[=============================>                              ] 49%
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Resolving links (4/6)                                                       
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
Printing pages (6/6)
[>                                                           ] Preparing
[==============================>                             ] Page 1 of 2
[============================================================] Page 2 of 2
Done                                                                      
Exit with code 1 due to network error: ContentNotFoundError

updated wkhtmltopdf

Traceback (innermost last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 54, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 43, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 66, in handle
    execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 89, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 532, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/templates/pages/print.py", line 94, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 29, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pdfkit/api.py", line 68, in from_string
    return r.to_pdf(output_path)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pdfkit/pdfkit.py", line 93, in to_pdf
    stderr=subprocess.PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
 OSError: [Errno 8] Exec format error

Maybe you have a file that is linked with a relative url like /files/image.png instead of http:..