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
27,585 sites
130
drupal.org

インストール

Drupal 11, 10, 9 v8.x-2.18
composer require 'drupal/entity_print:8.x-2.18'

概要

Entity Printは、Drupalのコンテンツエンティティ(Node、ユーザー、Commerceの商品など)やViewsを、PDF、Word文書(DOCX)、EPubなど複数の形式でダウンロード可能なドキュメントに変換できる包括的なPDF印刷ソリューションです。

このモジュールは軽量ながら強力なアーキテクチャを提供し、完全なテストカバレッジを備え、複数のPDF生成エンジン(DomPdf、wkhtmltopdf、TCPDF)をサポートしています。Drupalの表示モードとシームレスに統合され、管理者はエンティティ表示ページにどのエクスポートタイプを表示するか設定できます。

主な機能:サービスAPIを介したプログラムによるPDF生成、Views Bulk Operationsアクションによる一括ダウンロード、カスタマイズ可能なテンプレートとCSSスタイル、高度なカスタマイズのためのイベントシステム、エンティティタイプとバンドルごとの包括的な権限制御。

Features

  • あらゆるDrupalコンテンツエンティティ(Node、ユーザー、タクソノミーターム、Commerce商品など)をPDF、Word文書、またはEPub形式に変換
  • Entity Print Viewsサブモジュールで、露出フィルターと引数をサポートしたViews全体の印刷が可能
  • 複数のPDFエンジンをサポート:DomPdf(デフォルト、Composer経由で含まれる)、wkhtmltopdf(外部バイナリ)、TCPDF
  • 印刷エンジンごとに用紙サイズ、向き、DPI設定を構成可能
  • Extra Field統合により、エンティティ表示設定に「PDFを表示」リンクを配置可能
  • エンティティページにコンテキストに応じた印刷リンクを表示するBlockプラグイン
  • 複数のエンティティをPDFとして一括ダウンロードするViews Bulk Operations(VBO)アクション
  • Viewのヘッダー/フッターに印刷リンクを追加するViewsエリアハンドラー
  • Viewの各行に印刷リンクを追加するViewsフィールドハンドラー
  • PDF変換前に生成されたHTMLを確認できるデバッグモード(CSSスタイリングに便利)
  • HTML、CSS、ファイル名、印刷出力をカスタマイズするためのイベントシステム
  • アクティブなテーマとアタッチされたライブラリからのCSS自動収集
  • PDFに画像を直接埋め込むためのBase64画像フォーマッター
  • 保護されたリソースへのHTTP認証サポート
  • PDF内のプライベートファイルにアクセスするためのセッションCookie転送
  • PrintBuilderサービスを介したPDFの生成と保存のためのプログラマティックAPI
  • 印刷アクセスのためのエンティティタイプとバンドルごとの詳細な権限設定
  • インストール時にカスタマイズされた印刷レイアウト用の「PDF」表示モードを作成
  • カスタマイズ可能なentity-print.html.twigテンプレートによるテーマサポート

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
Entity Print /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.

権限 5
Administer Entity Print

Allow users to administer the Entity Print settings. This is a restricted access permission.

Bypass entity print access

Allow a user to bypass the entity print access permissions, enabling PDF generation for any entity they can view.

[Entity Type]: Use all print engines

Dynamically generated permission for each content entity type. Allows printing all bundles of that entity type.

[Bundle Label]: Use all print engines

Dynamically generated permission for each entity bundle. Allows printing entities of that specific bundle.

Access Printable version of View

Allow a user to view the printed version of a view (requires Entity Print Views submodule).

Troubleshooting 5
Images not appearing in PDF

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.

CSS styles not applied in PDF

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.

wkhtmltopdf not working

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.

Fonts not rendering correctly

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.

PDF generation times out

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.