Generating PDF on the fly with Kirby CMS

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:

1 Like

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

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!

Hi @kmajort,
I am looking for a solution to generate PDFs with Kirby. Could you maybe share a bit more on your solution? That would be great!

Hi, I created a custom panel field and i used Dompdf to create Pdf-files. This works fine and easy (html to pdf) when you create small files but when you need to create large pdf-files it is rather slow.

Would you mind to share some of your code?
I will have a look into the docs for panel fields of course but maybe you have some hints for me – for the panel field and for connecting to Dompdf (I will later use PriceXML or PDFreactor, but I think there wwon’t be a great difference on the installation part). That would be great!

1 Like

I’m interested as well. Can you share some code to use at least as a guideline, please?
Thank you!