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

1 Like

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