I continue to believe Kirby would be a nice framework to prepare documents for print.
There is an interesting explanation of how they do CSS templating for print :
Except when using PrinceXML or PhantomJS (does not support the awesome CSS printing features though), printing a HTML page to a PDF from PHP wonât give really good results. TCPDF creates crazy large files when using the HTML mode.
Creating a PDF from PHP powered codes gives (me) extreme good and small results.
I even use them to create official PDF-X documents for pre-press purposes, where I convert (s)RGB-colorspace to CMYK - with a nice Adobe converter.
But I do not âsimplyâ convert âaâ page to PDF -> I parse the code with Simple DOM, extract what I need, place a custom CSS on the content and spit out a decent PDF.
So, itâs possible - I use it for clients who create a page with high-res images on the fly (using a custom CMS) and they create the PDF-X in order to have it printed (booklets, cards, posters, etc).
Thanks @1n3JgKl9pQ6cUMrW and @lukasbestle
Iâve been toying around the idea for a while and Iâm trying to figure out the best way to do this.
I think itâs a bit beyond my coding capabilities at the moment, but Iâll try and dig into it!
Hi guys,
Did one of you suceed to have a âPrint this page in PDFâ button in Kirby?
I want to generate a PDF from a Kirby page, using a âprint.cssâ stylesheet.
Any idea?
We built the Coffee Variety Catalog this Summer, and uses print stylesheets extensively.
The PDFs you download here were all âgeneratedâ by an administrator by using the standard âPrintâ dialog in Chrome.
While it doesnât auto-generate the PDF, there isnât really much need, given that an editor will be publishing them at particular intervals (and users will only download a particular release), rather than an up-to-date-and-on-the-fly version.
We created a separate âreleaseâ template that threaded together content from throughout the site into a single page (which was backed by a blueprint that allowed a bunch of customizations and additional content to be added.
During development, we made extensive use of Chromeâs âEmulate CSS Mediaâ setting (see below).
We hope to open-source this project soon, but will need sign-off from the organization.
Thanks for the example! What I want to achieve is simplier : I just want to print single pages (ex.: a blog post), and not generate a PDF from several pages combined. The PDF is the content of the page, with a layout generated from a stylesheet âstyles.cssâ. If someone has time to make a plugin, I think it can be helpfull for many people!
In the end, I used Prince XML to generate the PDF by hand. It was for a pretty long doc (~60 pages) with content table, page numbers, footnotes and all.
Then ran it through the âprint PDFâ command on Chrome to take off the watermark. Worked really well but itâs still not âautomaticââŚ
I donât think you need a plugin for this. You can make your print stylesheet apply to print using the media directive in the <link> tag and then add a print button to the page (window.print()). Itâs a bit of manual work, but definitely the easiest way to print single pages to PDF.
Thank you! I know how to work with a print stylesheet, but the problem with the âwindow.printâ javascript button is that it open a print window instead of generate a downloadable PDFâŚ
Thatâs definitely true. I had a similar use-case before and simply âprinting to PDFâ was a good solution there (some operating systems like macOS support that by default). Of course thatâs not always viable.
Much more complex but doable is using some kind of PHP PDF library like proposed above.
I used TCPDF and its a nightmare. Its fine for things like tickets and one pagers - where you generate the elements directly without HTML conversion. HTML mode is extremely slow and just horrible. mPDF was better similar PHP library. Because TCPDF in html mode sometimes silently errors for strange reasons and does nothing (hard to debug). With mPDF you have some kind of security that the libary generates at least some PDF file or error output.
In the end its not worth it i think. Use print styles where you can.
If you end up going the PHP generator HTML route - be sure to feed it valid html (run it through php tidy or something like that).