Anyone experience with creating a PDF-file on the fly with Kirby3? Any tips and tricks are appreciated!
Some options suggested in a discussion on Slack:
TCPDF (and v2) : TCPDF is more maintained and there is also beta version of TCPDF 2 rewrite so i would check that out. It works great for things like tickets and invoices but its harder when you want to make things like articles that span multiple pages with pictures and different types of headings etc.
mpdf: If you need quick pdf that is not really important mpdf is fine
headless Chrome: https://github.com/GoogleChrome/puppeteer
https://cloudconvert.com/website-to-pdf api. its not free but might be cheaper than configuring mpdf
https://docraptor.com/ which has per document pricing and free but watermarked test documents. It uses prince xml as rendering engine:
(https://github.com/louis-ev/Papeterie) + Browsershot to generate the pdf (converts the page with a headless version of Chrome, https://github.com/spatie/browsershot) to benefit from the latest CSS syntax. But haven’t tried it yet.
Weasyprint service: https://weasyprint.org/
This can easily be integrated in a custom panel field/section? I have problems because i can’t use the global $page, $pages and $site variable there. I think i miss here something
What do you mean by integrate into the Panel? Generate a PDF when a button is clicked. As I mentioned, this is just a collection of suggestions that came up in the Kirby 3 Slack channel a while ago. I can’t tell you any more.
I have created PDF files in Kirby2 not yet in Kirby3 with mpdf.
But mpdf is really a mess if you need a perfect layout. but it has one of the best documentation. tcpdf documentation is hard to understand if you start with pdf creation.
You can use controller or templates with routes for creating as example.
I created also a pdf creation from the K2 panel with the opener plugin
It is actually not developed for K3.
What will you do exactly?
Hi, i did a test to create a pdf with dompdf. This works but the pdf is automatically downloaded into the downloadsfolder. I wonder if it is possible to save it locally in kirby or if it’s possible to send it immediately as an attachment in an email.
I’ve done a project using Prince recently, which is a very powerful and flexible tool (although quite expensive).
A few weeks ago I discovered WeasyPrint, which is actually not a service but an open source tool that seems to be quite similar to Prince in that it supports CSS pretty well. I have not tested it, but it looks very promising.
@kmajort All these tools generally support writing the PDF to disk, so you should be able to save the file into the
content directory or (to send it as PDF) into a temporary directory and then call the
$kirby->email() method on it.
thanks, works perfect now!