Error trying to generate pdf

I was getting 504 Gateway Time-out when trying to generate pdf … so i checked to see that wkhtmltopdf was not install so i did an apt-get install wkhtmltopdf now i get

root@erp-2:~# apt-get install wkhtmltopdf

Server Error

Traceback (innermost last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 60, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 50, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 19, in handle
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 36, in execute_cmd
    ret =, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 806, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/templates/pages/", line 182, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/", line 16, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/", line 68, in from_string
    return r.to_pdf(output_path)
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/", line 143, in to_pdf
    raise IOError("wkhtmltopdf exited with non-zero code {0}. error:\n{1}".format(exit_code, stderr.decode("utf-8")))
 IOError: wkhtmltopdf exited with non-zero code 1. error:
Unknown long argument --no-outline

  wkhtmltopdf 0.9.9

  wkhtmltopdf [OPTIONS]...  [More input files] 

  Converts one or more HTML pages into a PDF document, *not* using wkhtmltopdf
  patched qt.

General Options:
      --collate                       Collate when printing multiple copies
      --copies                Number of copies to print into the pdf                                      file (default 1)
      --extended-help                 Display more extensive help, detailing                                      less common command switches
  -h, --help                          Display help
  -O, --orientation      Set orientation to Landscape or Portrait
  -s, --page-size               Set paper size to: A4, Letter, etc.
      --password            HTTP Authentication password
  -p, --proxy                  Use a proxy
  -q, --quiet                         Be less verbose
      --username            HTTP Authentication username
  -V, --version                       Output version information an exit
Reduced Functionality:
  This version of wkhtmltopdf has been compiled against a version of QT without
  the wkhtmltopdf patches. Therefore some features are missing, if you need
  these features please use the static version.

  Currently the list of features only supported with patch QT includes:

 * Printing more then one HTML document into a PDF file.
 * Running without an X11 server.
 * Adding a document outline to the PDF file.
 * Adding headers and footers to the PDF file.
 * Generating a table of contents.
 * Adding links in the generated PDF file.
 * Printing using the screen media-type.
 * Disabling the smart shrink feature of webkit.

  If you experience bugs or want to request new features please visit 
  , if you have any problems
  or comments please feel free to contact me: see

I am still having issue with this as a work around i tried a new install on a new server, and then importing my data but could not get the data import to work correctly … now i get now post on either of my topics argh

other topic here

@c0mputerking I don’t think apt-get install works for wkhtmltopdf

You need to install 0.12.2

Thank you for your reply rmahata having alot of difficulty getting pdf working again i have the following version installed

root@erp-2:~# wkhtmltopdf -V
wkhtmltopdf (with patched qt)

Do not remember exactly where i got this version of wkhtmltopdf from … i think i tried apt-get but could not get it to work with erpnext so then tried a deb file from somewhere i think , what version is Erpnext using ie where do i download matching to erpnext

would it be this which is a bit old but whatever works right ?

Really stumped here not sure where to look is there a log file to see my error?

Tested wkhtmltopdf and it works

I tested wkhtmltopdf and it works but cannot get erpnext to do pdf just error 504 Gateway timeout in the browser argh google.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)

HI @c0mputerking facing same issue, wkhtmltopdf works fine but erpnext giving error 504 Gateway timeout in browser.

did you find any solution?

Im having the same issue. I have tried apt-get 0.9.9, a repo for apt-get to 0.13, manual install of 0.12, and 0.13, and now im back to a deb of 0.12.2 and i get the gateway timeout. All other install threw errors on an error page

Update: I have found it is only when trying to create a PDF that has images on products. If i make a quote with items with no images, it generates fine. This seems to be the case with web linked images as well as local uploaded images

Update: I have found that setting my site_config.json hostname to localhost will produce a PDF now, but the formatting is way off and no pictures or my letterhead will show up.

I am having the same problem and when I update ./sites//site_config.json to add “host_name”: “http://localhost”, doesn’t make a difference.

@wsxedcr @Clayton_Mannerow

First uninstall wkhtmltopdf using - sudo apt-get remove --purge wkhtmltopdf

then try this steps Wkhtmltopdf unpatched Qt error on ERPNext V7 - #6 by kolate_sambhaji

1 Like

I did that already last night, I am at w/ qt patched, and I am still geting timeout on pdf generation.

The funny thing is, if you run bench start, the problem doesn’t happen, it’s only when you use production with nginx, then the problem occurred.

1 Like

Hi All

getting the same issues as above users are… I have tried generating PDF under Purchase Orders, Expense Claims, Company lists and get a 504 bad gateway error. If i go under a project and i try to view as PDF, then the below error shows

	Traceback (most recent call last):

File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 54, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 19, in handle
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 36, in execute_cmd
ret =, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 890, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/”, line 48, in download_pdf
html = frappe.get_print(doctype, name, format, doc=doc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 1173, in get_print
html = build_page(“print”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/”, line 137, in build_page
context = get_context(path)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/”, line 18, in get_context
context = build_context(context)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/”, line 84, in build_context
update_controller_context(context, context.controller)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/”, line 46, in update_controller_context
ret = module.get_context(context)
File “/home/frappe/frappe-bench/apps/frappe/frappe/www/”, line 41, in get_context
File “/home/frappe/frappe-bench/apps/frappe/frappe/www/”, line 138, in get_html
“layout”: make_layout(doc, meta, format_data),
File “/home/frappe/frappe-bench/apps/frappe/frappe/www/”, line 273, in make_layout
IndexError: list index out of range

Was any solution found to this. I have the same issue and as Clayton_Mannerow said the timeout issue is only when there are image files.

If I use letterhead (checkbox) while printing for e.g. purchase order then the pdf times out. My letterhead has images (.png). However if I do not use letterhead it generates the pdf just fine.

Any help is appreciated.

If this is something to do with the OS - i am on UBUNTU 64 bit.

Found the reason for this issue…

It is to do with file permissions. As the letterhead images are ‘by default’ put in the /private folder they seem to be inaccessible to wkhtmltopdf, resulting in the time-out.

If you move the images being used to the public folder and then try generating the pdfs it turns out fine.

Probably changing file permissions in the /private folder may work too but i have not tried this.

@c0mputerking @tyag
Hi,Did you solve this problem? I have also met

You must be using Letterhead file as private.
If you keep the images private then the PDF will not generate.

Always make sure that all the images used in the pdf print should have images to be public.