Regarding Kirby integration: You can simply drop the prince.php into your plugin directory and then create another plugin that uses the library in the Kirby context. A good way of implementing dynamic PDF generation could be to create a route that serves the PDF of a given page:
// Make sure to load Prince before this plugin
kirby()->plugin('prince');
kirby()->routes(array(
array(
'pattern' => 'pdf/(:all)',
'action' => function($path) {
$page = page($path);
$prince = new Prince('<path>');
// Do stuff with $page and generate HTML code for the PDF
// You could use an HTML template inside your plugin
}
)
));
Thanks @lukasbestle!
This looks really exciting! Have you tried it yourself?
Would you recommend using Prince? Or do you know of a better (cheaper) option?
I have used Prince for a project that required dynamic HTML to PDF conversion. Prince is the only good library for this use-case.
If you only need a static template (the same layout, only different content), I can highly recommend TCPDF. It has an awful API but once you know how to use it, it works pretty well. And it’s free and open source.
If you want to use TCPDF, you can swap out the word prince with tcpdf in my previous post. It works with Kirby in the same way.