Big differences between PDF page and preview/Print button page

I wondered about how fast you were able to provide a related report on SO :slight_smile: - unfortunately you were right, no real solution so far (at least not without a lot of JS).

I just wanted to give you and others a final update on my case: it turned out to be quite a long journey in order to get Print formats look the way I wanted. My final solution is as follows:

My final solution:

Those utilities aren’t public yet. If there is high demand, I might consider it, though.

  • Created custom Frappe app which will add a jinja function in order to pre-calculate HTML element’s height (based of css styles). This gives me maximum freedom to calculate page-breaks, page numbers e.g. in advance - even with mixed html contents (like for e.g. adding an image within a table row). This solution allows for html-to-pdf generation too without any third party app (like frappe-pdf).
  • Since playwright has a pretty bad cold-boot time, I’m using a standalone python app on my Server, which handles the calculation and pdf-generation stuff.

I did indeed try several other solutions, which might have saved some effort and time, but I wasn’t able to find any good option:

  • Trying to trick html into larger table headers: Very hacky approach which is quite limited since print-preview does still looks different.
  • Pre-calculate html element-size using python libraries like pillow: Not suitable with mixed html content - only possible for basic texts.
  • Weasyprint: Might have been an option, but with high costs. I noticed however, that Weasyprint is already part of Frappe, even if it isn’t widely used yet.

Thank you @Yamen_Zakhour for your support!

4 Likes

Congratulations.

My humble suggestion. Release it in public domain, even if there is no demand.

After a couple of months, you will find many persons using it, and a few might improve it :wink:

Update: We just found the holy grail for better prints.

Split Print Format table automatically into pages based on rendered size.

Using our custom app’s jinja function, we are now able to split the table rows according to a given “max-size” per page, taking print format styles into account. You just pass the whole table html and will get a paginated version back. Easy as that.

We’re still finishing everything up and are planning to make it public. Might be our contribution to the frappe community :slight_smile: :fireworks:

1 Like

hi, I am waiting for your solution
Will it include difference in the cell height in PDF and print too? If I use PDF button the cell height is very high, with bigger font

Hi @auliabismar
We’re still planning on releasing it for public - but there’s a lot to do for a stable release.

There won’t be any differences between preview and actual print. If you set the css accordingly, you will be able to specify any cell height/padding.

So far, our solution will be released approx. around February/march and will be mainly focused on jinja print formats.

Update: We’re on track and able to release a first beta version by mid/end of February. After discovering an even better solution, we switched over and got a pretty awesome app now with lots of improvements over the standard print formats.

Waiting…

Quick update for all those waiting, as the first beta will be delayed a little: In favor of stability & reliability, we replaced one underlying library with a custom-made. This will delay the first beta to approx. mid of April, but will add further simplicity as well.
So… good things take time.

New Chrome Headless is now available for testing locally in develop version :tada: ( FC support is pending ). feat: Chrome PDF Generator by maharshivpatel · Pull Request #399 · frappe/print_designer · GitHub

1 Like

Hi @Maharshi_Patel
Thank you, great news for all users of Print designer and it’s future (which is definitelly very promising) :slight_smile: .

Our solution will provide a different, more Jinja oriented approach:

  • Free control over content with jinja and full html/css support
  • Printpreview 1:1 identical look to the final PDF (preview is rendered clientside, therefore more performant)
  • Dynamic header/footer
  • Custom page formats

I know Print Designer does fullfill a lot of those needs, but still not all. This was the initial reason for our custom app. However, I’d love to see them implemented in Print Designer too in the future :slight_smile:

@neocode what i shared is new pdf generation backend for frappe ( not limited to print_designer ). It’s uses Chrome headless rendering. i shared this as you earlier mentioned it in the post. Thank you.

Ah, I see. Thank you :slight_smile:

Does your solution work on version 14? If so, I am really looking forward to it.

Interesting.

Is it released?

almost… a first alpha release should be ready this week - stay tuned :slight_smile:

(There were some unexpected issues, which made the final app even better in the end)

So there we are…

…after over 298 commits across 3 repos, I’m proudly presenting the first early-alpha release of Frappe Betterprint

You might as well take a look into the docs

Please note, it’s an early-alpha release - so expect breaking changes!

A quick overview of the features:

  • Universal Layout: Preview/Printview/PDF - they look just the same.
  • Full, modern CSS support: Flexbox, W3C standards - all printed with headless Chromium.
  • Individual page size per Print Format: Independent PDF size :smile:
  • Preview & support for any page size (even A0 or larger page size is supported)
  • Dynamic Headers & Footers: Apply different content per Page, add running numbers e.G.
  • Parallel use of regular Print Formats and Print Designer possible
  • better_page_break() Jinja function for quick & easy page-breaks
  • [comin soon] Page ranges: Add different styles to parts of your page
  • [comin soon] PDF-worker to generate PDFs even faster

What’s next?

I’m hoping to get some feedback from early tester - feel free to open an issue or submit a commit or feature request on our github repo GitHub - neocode-it/frappe_betterprint: Frappe app with advanced print functions or reply with any kind of questions & feedback to this message.

We’ll keep going to make frappe_betterprint even better to it’s first release. Keeping you updated. (One might as well give the repo a star and watch for releases on Github)

6 Likes

It will be only Frappe v15 onwards…

Thanks for your conyribution. Does it support the concept of page footer and last page footer?

So far we have been trying with all solutions exists in frappe and the control of footer is still a challenge.

Thanks