entity_print_css_injector
Entity Print CSS Injector is a Drupal module that improves the PDF output generated by Entity Print by automatically embedding CSS styles from the Asset Injector or from a static folder.
This ensures that all PDF documents maintain a consistent and professional layout without requiring theme-specific preprocessing hooks. The module is designed to work seamlessly with wkhtmltopdf and provides reliable formatting across all themes used on the site.
Features
The module automatically detects and includes CSS from the Asset Injector (prefixed by epcss_) AND from files located in web/sites/default/files/static/entity_print_css/.
It works independently of the active theme, requires no manual modifications to theme files, and embeds the CSS inline to avoid path issues during PDF rendering.
It is fully compatible with Entity Print and the wkhtmltopdf renderer.
Post-Installation
After enabling the module, on Debian-based systems, install wkhtmltopdf using the command sudo apt install wkhtmltopdf.
In the Entity Print configuration, select the “Php Wkhtmltopdf” renderer and provide the path to the wkhtmltopdf executable.
Set the DPI to 300 to ensure high-resolution output.
Step by step:
- On Debian-based systems, install wkhtmltopdf:
sudo apt install wkhtmltopdf - In the Entity Print configuration, specify the path to wkhtmltopdf after selecting the “Php Wkhtmltopdf” renderer
- Set the DPI to 300 to ensure crisp and high-resolution PDF output
- Optionally, place a css/pdf.css file in the active theme if the Asset Injector is not used
Additional Requirements
The Asset Injector is not directly a requirement, but a good hint to change the style at runtime.
The asset injector files need to have a prefixed machine name epcss_.
The pdf generator only supports plain CSS.
Preprocessor languages such as Sass, Less, or other CSS compilation features are not supported and will not be applied in the PDF output.