PDF is not working in v14

Hi, we are using Debian 11 and how to install this?

While I’ve:
wkhtmltopdf 0.12.6 (with patched qt)

Does wkhtmltopdf -V report same?

Result is:
wkhtmltopdf 0.12.6 (with patched qt)

The error I am seeing is:

Traceback (most > recent call last):

File “apps/frappe/frappe/app.py”, line 69, 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 1599, in call
return fn(*args, **newargs)
File “apps/frappe/frappe/utils/print_format.py”, line 129, in download_pdf
frappe.local.response.filecontent = get_pdf(html)
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: ConnectionRefusedError

with wkhtmltopdf 0.12.6.1 (with patched qt). I wonder if there are more than one wkhtmltopdf installed?

How to check and fix this.

Check the version of wkhtmltopdf like so

apt show wkhtmltopdf

it should show something like this

To install in Debian 11

wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.bullseye_amd64.deb

sudo dpkg -i wkhtmltox_0.12.6.1-2.bullseye_amd64.deb

sudo cp /usr/local/bin/wkhtmlto* /usr/bin/

sudo chmod a+x /usr/bin/wk*

To install in Ubuntu 22.04

wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb

sudo dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb

sudo cp /usr/local/bin/wkhtmlto* /usr/bin/

sudo chmod a+x /usr/bin/wk*

And also add the host_name in site_config.json

"host_name": "https://yourdomainname"

Network error is usually when wkhtmltopdf can’t resolve or need the fully resolved URLs to the assets

1 Like

Hi

On the 22.04 install here I can invove wkhtmltopdf from the command line without copying to /usr/bin/.

frappe@ubuntu:~$ which wkhtmltopdf
/usr/local/bin/wkhtmltopdf
frappe@ubuntu:~$ wkhtmltopdf -V
wkhtmltopdf 0.12.6.1 (with patched qt)

In this instance the url of the site is the ip.of.the.host:8080 , I’m not sure what to enter in site_config.json

The apt show returns the same.

Can you confirm that the problem does not appear on a Ubuntu 22.04 host with v14?

Same with me, as I’m also using IP with port.

Yes I can confirm wkhtmltopdf is working in Ubuntu 22.04 and with version 14 and develop of Erpnext and Frappe

Well as mentioned before since you are using using IP with port

Add that instead of domain name like so in site_config.json

“host_name”: “https://IP address:port”

1 Like

Adding the stanza slowed the site page loads greatly, but the problem still remains. May I know if you have letsencrypt deployed ? It is not here and I’m wondering if there is a ssl element here.

Thanks

Hi @smino

Sorry I presumed you had ssl (let’s encrypt) installed. If you use Https then you need to have ssl installed

If no ssl just remove the Https and could you try

“host_name”: “ipaddress:port”

This didn’t work for me:

Hi,

I think it is common_site_config.json file in sites folder. Try that instead, I will do the same when I have time.

/home/frappe/frappe-bench/sites/common_site_config.json , I believe.

First you mentioned another file but now I changed this file too, but not working:

I restarted the bench and found this error:
Traceback (most recent call last):
File “/home/erpnextuser001/.local/bin/bench”, line 10, in
sys.exit(cli())
File “/usr/local/lib/python3.9/dist-packages/bench/cli.py”, line 80, in cli
bench_config = get_config(“.”)
File “/usr/local/lib/python3.9/dist-packages/bench/config/common_site_config.py”, line 30, in get_config
return get_common_site_config(bench_path)
File “/usr/local/lib/python3.9/dist-packages/bench/config/common_site_config.py”, line 38, in get_common_site_config
return json.load(f)
File “/usr/lib/python3.9/json/init.py”, line 293, in load
return loads(fp.read(),
File “/usr/lib/python3.9/json/init.py”, line 346, in loads
return _default_decoder.decode(s)
File “/usr/lib/python3.9/json/decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python3.9/json/decoder.py”, line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 21 column 15 (char 589)

Try adding a comma at the end of the hostname line.

nope

it has to be in the site_config

Try adding like so… since not https

“host_name”: “http://ipaddress:port”

Additional thought … Are you guys using a VPS or localhost ??

I have v14 on 22.04, v13 on 22.04 and v13 on 20.0x . The 22.04 instances have wkhtmltopdf 0.12.6.1 (with patched qt), neither of which work and the Ubuntu 20 has 0.12.3 , which works. All are virtualbox vm’s. I did try http rather than https and no difference , and the addition to common_site_config.json slowed the site to a crawl.

Ah in that case you need to additionally add the IP of the VM to /etc/hosts file as well

I am also running v14 and develop in WSL… In both cases wkhtmltopdf working fine with localhost