bkm
April 8, 2022, 2:59pm
1
Using ERPNExt v13.11.1 and I am cannot figure out how to get the PDF button to use my selected/defaulted print format.
For eaxmple:
I create a Purchase Order. I print the purchase order and it looks like this:
However, I need to make a PDF file out if it and send it to another co-worker. So I click on the following PDF button at the top of the screen:
And it generates a PDF of the Purchase order that doesn’t look anything at all like what I want. See pic:
I need to know if there is a way to alter the behaviour of the PDF button so it generates the same thing that I am able to print?
What am I missing?
BKM
peterg
April 8, 2022, 4:41pm
2
I can’t quite tell what’s going on here just from the screen grabs. Does it look like the css and external images aren’t getting loaded correctly? If so, that’s a well-known quirk of wkhtmltopdf.
Continuing the discussion from Multitenant production server setup :
I added a second site based on the linked Topic. This worked without any problem on first sight.
However the formatting of PDF’s created from a SINV and other documents (by clicking the PDF button on the print preview) does not work anymore. The entire Layout (Logo on Top, Layout of the print) is lost after clicking the PDF button.
The only workaround I can get running is to use PRINT (instead of PDF) from the Print Preview …
Agree with @peterg , and empathize with you @bkm .
I constantly struggle with creating clean PDFs from Print Formats. I have a few Open Issues on my plate right now, where images aren’t being displayed. Or the layout (columns, alignment, spacing) is drastically different.
I think sometimes the main CSS framework used by ERPNext (Bootstrap ), isn’t properly loaded when wkhtmltopdf
does the conversion into the PDF.
I especially struggle in development environments where I’m using port-based Sites, and no TLS. The routing isn’t always clean, so the wkhtmltopdf
cannot fetch all the assets it wants.
1 Like
nasir
April 11, 2022, 6:11am
5
Hi @bkm ,
I too have faced the same issue. I use a custom format, and the PDF button just completely breaks the formatting. wkhtmltopdf is at fault here.
As a workaround, I use the following.
Click print on button as you would normally do when a hard copy needs to be printed.
In printers, select Print to PDF (or Save as PDF)
While this too sometimes breaks formatting, with some tweaks it should be working.
Regards
Nasir
hi @bkm
What version of wkhtmltopdf are you on ???
You need to upgrade wkhtmltopdf to the latest stable 0.12.6.
It should in most case solve the issue
Follow-up to this thread.
Today, I finally gave up on trying to link an image (logo) in my Print Format. No matter what I tried, 'wkhtmltopdf'
threw an error.
So, I’ve changed my strategy completely:
Use an .svg logo.
Opened the logo in a text editor, and copied the raw XML text.
Created a new DocType: 'Vector Images'
Pasted the vector text into the DocType.
Wrote a Python function for my Sales Order, to fetch the data from 'Vector Images'
Opened my Print Format.
Remove the old way I was doing it, with <img>
, anchors, or links.
Added this instead:
{{ doc.get_my_vector_logo() }}
So now, my logo is -embedded - inside the HTML as SVG.
No links = No frustrating errors from 'wkhtmltopdf'
when it tries to create a PDF. And the image shows up!
If I want to edit my logo, or use different ones, I have them all stored in my new DocType.
1 Like
bkm
April 19, 2022, 2:36pm
10
Any possibility that you could point me to the method you used to upgrade your version of wkhtmltopdf?
Am I supposed to use the ones with qr patch and is there a version specific to frappe?
BKM
peterg
April 19, 2022, 2:42pm
11
Here’s a link, to yourself no less!
I had the same problem as in this post:
What helped me was to update wkhtmltopdf:
wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb
dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb
Above commands are for Ubuntu 18.04. You’ll need the right url for your system.
The command works but make sure you use an updated URL from the link Raffael shared
bkm
April 19, 2022, 2:58pm
12
LOL
Back then it was me playing moderator not actually fixing a problem. But thanks for the redirect. It is kinda funny. I will have to try this now.
BKM
bkm
April 19, 2022, 3:20pm
13
Yeah… the command works, but the overall fix does not.
At this point I can click on the PDF button in the upper right corner of a Sales Invoice and it does create a good PDF file.
However, if I try to email the Sales Invoice from the email function in the drop-down list on the Sales Invoice, it still comes out all messed up.
So this fix got it to create better PDF’s when you click the PDF button but it did not fix the emailing of Sales Invoices or Purchase Orders. Those are still messed up.
I guess that is at least a half step forward
Any ideas?
BKM
hi @bkm
Try setting the host_name to the IP address in your site_config.json should solve that
2 Likes
bkm
April 19, 2022, 3:50pm
15
Thank you @centaur
While the wkhtmltopdf version upgrade fixed the PDF generator, the hostname entry in site_config.json fixed the email problem.
BKM
2 Likes
I tried this solution like this:
"host_name": "https://xxx.xxx.xxx.xxx"
I also tried it using my domain name:
"host_name": "https://mydomain.com",
Both did not work. Did I do it wrong or this solution no longer works?
Hi @flexy2ky
Could you elaborate on what exactly the problem is ??
What is your wkhtmltopdf version ?
@centaur Thanks for the quick reply.
PDFs don’t get generated with the letterhead when emailing any document like sales invoice. Even when the pdf button is clicked in the print view, the generated PDF does not contain the letterhead even though the print view shows the letterhead.
This is my wkhtmltopdf version: wkhtmltopdf 0.12.6
Any help I can get will be appreciated.
Hi @flexy2ky
I presume you must have installed wkhtmltopdf using the sudo apt method ( this doesn’t contain the Qt patch)
If so you could first remove the version by simply doing
sudo apt remove wkhtmltopdf
Then go to the wkhtmltopdf website and select the package appropriate to you OS version and follow the steps below
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*
Check your version now
using either
wkhtmltopdf --version
will show up the below
or
apt-cache show wkhtmltopdf
will show up the below
5 Likes
@centaur Thanks a gazillion!!! Your solution above worked!!! This is very much appreciated