Generating PDF on the fly with Kirby CMS


#1

Anyone experience with creating a PDF-file on the fly with Kirby3? Any tips and tricks are appreciated!


#2

Some options suggested in a discussion on Slack:


#3

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:


#4

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.


#6

Hi,
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?

Cheers


#7

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.


#8

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.


#9

thanks, works perfect now!