Entity Print
Entity Print allows you to print any Drupal entity or View to PDF, Word Document, or EPub formats using configurable PDF engines like DomPdf, wkhtmltopdf, or TCPDF.
entity_print
Install
composer require 'drupal/entity_print:8.x-2.18'
Overview
Entity Print is a comprehensive PDF printing solution for Drupal that enables any content entity (nodes, users, commerce products, etc.) or Views to be converted to downloadable documents in multiple formats including PDF, Word Document (DOCX), and EPub.
The module provides a lightweight yet powerful architecture with full test coverage, supporting multiple PDF generation engines (DomPdf, wkhtmltopdf, TCPDF). It integrates seamlessly with Drupal's display modes, allowing administrators to configure which export types appear on entity view pages.
Key capabilities include: programmatic PDF generation via services API, bulk download via Views Bulk Operations actions, customizable templates and CSS styling, event system for advanced customization, and comprehensive permission controls per entity type and bundle.
Features
- Convert any Drupal content entity (nodes, users, taxonomy terms, commerce products, etc.) to PDF, Word Document, or EPub format
- Print entire Views with the Entity Print Views submodule, supporting exposed filters and arguments
- Multiple PDF engine support: DomPdf (default, included via Composer), wkhtmltopdf (external binary), and TCPDF
- Configurable paper size, orientation, and DPI settings per print engine
- Extra field integration allowing 'View PDF' links to be placed in entity display settings
- Block plugin for displaying print links contextually on entity pages
- Views Bulk Operations (VBO) action for batch downloading multiple entities as PDF
- Views area handler for adding print links to View headers/footers
- Views field handler for adding print links to each row in a View
- Debug mode for viewing generated HTML before PDF conversion (useful for CSS styling)
- Event system for customizing HTML, CSS, filenames, and print output
- Automatic CSS collection from active theme and attached libraries
- Base64 image formatter for embedding images directly in PDFs
- HTTP authentication support for protected resources
- Session cookie forwarding for accessing private files in PDFs
- Programmatic API for generating and saving PDFs via the PrintBuilder service
- Granular permissions per entity type and bundle for print access
- Creates a 'PDF' view mode on installation for customized print layouts
- Theming support with customizable entity-print.html.twig template
Use Cases
Generate Downloadable Invoices
Create PDF invoices from Commerce orders by enabling Entity Print on the order entity type, configuring a 'PDF' view mode with invoice layout, and adding the 'View PDF' field to the order display. Users can click the link to download their invoice.
Bulk Print Certificates
Use Views Bulk Operations with the Entity Print action to select multiple certificate nodes and generate a combined PDF download. Configure the action in Views and select 'Download PDF' from the bulk operations dropdown.
Print Reports from Views
Enable the Entity Print Views submodule and add the 'Global: Print' area handler to a View's header. Users can print the entire view output including all rows matching their exposed filter criteria.
Custom PDF Styling
Create entity-print--node--article.html.twig in your theme to customize the print layout for articles. Add CSS files targeting the 'pdf' view mode in your theme's libraries to style the PDF output differently from the website.
Programmatic PDF Generation
Use the entity_print.print_builder service to generate PDFs in custom code or queue workers. Call savePrintable() to save PDFs to disk or deliverPrintable() to stream to the browser. Subscribe to events to customize output dynamically.
Debug PDF Styling
Append /debug to any print URL (e.g., /print/pdf/node/1/debug) to view the raw HTML that will be converted to PDF. Use this to debug CSS issues and verify content rendering before final PDF generation.
Tips
- Create a dedicated 'PDF' view mode for each content type to control exactly what appears in printed documents without affecting the website display.
- Use the /debug endpoint (e.g., /print/pdf/node/1/debug) during development to see the HTML before it's converted to PDF.
- Add print-specific CSS in your theme by creating CSS files that target the entity-print template classes.
- For custom filenames, subscribe to the entity_print.print.filename_alter event and modify the filename array.
- When printing in CLI context (drush, queue workers), configure the Base URL setting to ensure proper absolute URL generation.
- Use the Base64 Encoded Image formatter for image fields in the PDF view mode to avoid external URL loading issues with some PDF engines.
Technical Details
Admin Pages 1
/admin/config/content/entityprint
Configure the default print engine for each export type (PDF, EPub, Word Document) and global settings for PDF generation including default CSS, force download behavior, and base URL for CLI usage.
Permissions 5
Troubleshooting 5
Ensure 'Enable Remote URLs' is checked in Dompdf settings. For private files, the module automatically forwards session cookies. Consider using the Base64 Encoded Image formatter for problematic images.
Add CSS to your theme targeting the 'pdf' view mode or use the entity_print library. Check that CSS files are properly attached via libraries.yml. Use the /debug endpoint to inspect applied styles.
Verify the binary path in settings is correct. Ensure the wkhtmltopdf binary is executable by the web server user. Check server logs for permission errors.
Use web-safe fonts or ensure custom fonts are properly embedded. The default CSS uses DejaVu Sans which is commonly available. For custom fonts with DomPdf, configure the font directory settings.
For large documents or Views, increase PHP max_execution_time. Consider using wkhtmltopdf for better performance with complex HTML. For Views, limit the number of items per page.
Security Notes 5
- The HTTP Authentication credentials for PDF engines are stored in plain text in configuration. Use environment variables or secrets management for sensitive credentials.
- Verify SSL peer settings should only be disabled in development environments, never in production.
- PDF generation can be resource-intensive. Consider rate limiting print requests in high-traffic environments.
- The 'administer entity print' permission is marked as restricted access and should only be granted to trusted administrators.
- When using savePrintable() programmatically, be aware that the default scheme is 'public' which makes files web-accessible. Use 'private' scheme for sensitive documents.