Pimcore Web-to-Print Quickstart
What you’ll learn with this guide
This guide will show you how to configure and use Pimcore Web-to-Print functionality in administration.
Where to use
Suppose you have a list of products that need to be available in PDF format or create a catalog showing new products in PDF format. In that case, the easiest way to gather all products and convert them into PDF files is using Pimcore's Web-to-print functionality.
Solution
Web-to-Print settings
Before printing, let's check Web-to-Print settings. There you can configure which renderer to use and set their specific settings.
To create and use Web-to-Print documents (PrintPage and PrintContainer), you have to enable them in the settings.
Which renderer to use?
Currently, Pimcore supports wkhtmltopdf and PDFreactor renderers.
Wkhtmltopdf
For the wkhtmltopdf renderer, it is required to have it on a server (via the standard installation or single binary file), then in the configuration, you only need to set the path to it.
Additionally, you can set specific options which will be used when generating PDF.
You can find more options for wkhtmltopdf renderer at their official website.
PDFreactor
PDFreactor is used as a web service that doesn't require any installation. Instead, all PDF generation requests can be sent to their API. PDFreactor also provides an option where it can be installed on a server, more about that and details on a free trial, pricing, and other deals can be found on their official website.
Additional options for PDF generation can be set on print documents (details below).
Both renderers have Hostname input at the bottom of Web-to-print. Make sure that you enter your corresponding domain.
PrintPage
PrintPage is a document on which you can add content using Pimcore area bricks, editables, and other elements. Unlike other documents, PrintPage with "Edit" and "Preview" modes also has "Generate & Preview PDF" mode, which alongside options to generate and download PDF, allows to additionally set specific PDF settings for that document. Those options for additional settings are only available for PDFreactor renderer. For wkhtmltopdf options, they have to be defined in Web-to-Print settings.
In the "Settings" tab of that document, you still need to define Controller and Action, which will have the logic required to gather and display data shown in the PDF.
PrintContainer
PrintContainer is a particular type of document with a "Generate & Preview PDF" mode, but it doesn't have modes for editing content like PrintPage does. Instead, it is used to group PrintPage documents. One PrintContainer can have multiple nested PrintContainers. Additionally, that logic can be applied by setting an Action and Controller in the "Settings" tab.
Troubleshooting
If you are using wkhtmltopdf renderer and you get an error saying something like "QXcbConnection: Could not connect to display", which is an issue within wkhtmltopdf for Debian repositories. To fix this, you will need to install xvfb, a display server required to run wkhtmltopdf. Once installed, you have to set in in wkhtmltopdf path e.g. “xvfb-run /usr/local/bin/wkhtmltopdf”
If images are not showing when using wkhtmltopdf - there are a couple of reasons why this might happen. First, check if you have entered Hostname in Web-to-Print settings. If they are still now showing, check if that image is downloadable from the server, e.g., if the server is on Linux OS, you can run:
wget “https://yourdomain.com/path/to/image.png”
If that also is not working, you can switch to the file URI scheme ("file://") while fetching images and other assets. Image source would then be, e.g., src="file:///home/user/image.png". When using that option, make sure to add an option "--enable-local-file-access" in Web-to-Print settings for wkhtmltopdf.
Does it work?
If you've set everything up correctly according to this guide, then in PrintPage or PrintContainer, when generating a PDF, you should be able to see and download the PDF once it's generated. If it doesn't show at first and there are no errors, try refreshing that document or generating again.