PDF Generation in Drupal

pdf generation

It is nice when a user can click a button and generate a PDF. Over the last few months, I have added PDF generation to many projects. Examples of PDF generation include order invoices, sell sheets, webform submission results, and general node to PDF generation. 

When tasked at generating PDFs, I have been applying the dompdf library. The dompdf library implements the most versatility by using HTML and CSS to generate PDFs.  Therefore, giving the most flexibility for custom theming.  

Example 1

The most recent PDF generation task I completed was for Drupal commerce order invoices.  I leveraged twig templates to provide as much flexibility as possible, which allowed me to incorporate a special entity view mode and for additional block regions.  The new entity view display allows website admins to add, remove or rearrange order fields, and the additional block regions allowed for adding additional blocks throughout the template.  The flexibility of the Drupal interface not only provides a way for website admins to generate order invoices but also allows them to modify the layouts of the PDF invoice.

Example 2

In a past Drupal 8 commerce project, I have also automated the process to generate picket tickets upon orders reaching a specific state in the commerce order workflow. 

The dompdf library has been enjoyable and straightforward to use and I intend to use this library for future PDF generation projects.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.