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/app.py", line 60, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 50, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 19, in handle
    execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 36, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 806, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/templates/pages/print.py", line 182, in download_pdf
    frappe.local.response.filecontent = get_pdf(html)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/pdf.py", line 16, in get_pdf
    pdfkit.from_string(html, fname, options=options or {})
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/api.py", line 68, in from_string
    return r.to_pdf(output_path)
  File "/home/frappe/frappe-bench/env/src/pdfkit/pdfkit/pdfkit.py", 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



Name:
  wkhtmltopdf 0.9.9

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

  
Description:
  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.

Contact:
  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 0.12.2.1 (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 http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-jessie-amd64.deb 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

http://google.com google.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

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 0.12.2.1 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/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 54, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 36, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 890, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/print_format.py”, line 48, in download_pdf
html = frappe.get_print(doctype, name, format, doc=doc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1173, in get_print
html = build_page(“print”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py”, line 137, in build_page
context = get_context(path)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/context.py”, line 18, in get_context
context = build_context(context)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/context.py”, line 84, in build_context
update_controller_context(context, context.controller)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/context.py”, line 46, in update_controller_context
ret = module.get_context(context)
File “/home/frappe/frappe-bench/apps/frappe/frappe/www/print.py”, line 41, in get_context
no_letterhead=frappe.form_dict.no_letterhead),
File “/home/frappe/frappe-bench/apps/frappe/frappe/www/print.py”, line 138, in get_html
“layout”: make_layout(doc, meta, format_data),
File “/home/frappe/frappe-bench/apps/frappe/frappe/www/print.py”, line 273, in make_layout
page[-1][‘columns’][-1][‘fields’].append(df)
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.

3 Likes