How do I get the PDF generator to use my Print Format?

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:
Example%20PO2

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

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.

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

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.

  1. Click print on button as you would normally do when a hard copy needs to be printed.
  2. 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 ???

wkhtmltopdf v0.12.5

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:

  1. Use an .svg logo.
  2. Opened the logo in a text editor, and copied the raw XML text.
  3. Created a new DocType: 'Vector Images'
  4. Pasted the vector text into the DocType.
  5. Wrote a Python function for my Sales Order, to fetch the data from 'Vector Images'

Opened my Print Format.

  1. Remove the old way I was doing it, with <img>, anchors, or links.
  2. 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

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

Here’s a link, to yourself no less! :smiley:

The command works but make sure you use an updated URL from the link Raffael shared

LOL :rofl:

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 :crazy_face:

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 :roll_eyes:

Any ideas?

BKM

hi @bkm

Try setting the host_name to the IP address in your site_config.json should solve that

2 Likes

Thank you @centaur :star_struck:

While the wkhtmltopdf version upgrade fixed the PDF generator, the hostname entry in site_config.json fixed the email problem.

BKM :nerd_face:

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

image

or

apt-cache show wkhtmltopdf

will show up the below

4 Likes

@centaur Thanks a gazillion!!! Your solution above worked!!! This is very much appreciated :smiley: