[Drupal] How to handle PDF generation of custom path using MPDF module in Drupal

| | 1 min read

I had a requirement in one of my Drupal project to generate PDF from HTML. I had implemented the PDF file from HTML using the module MPDF. Let me explain you the following configurations for its working :

  • Download the Drupal 'libraries' module and extract it in 'sites/all/modules/'.
  • Download pdf_using_mpdf.tar.gz from 'https://www.drupal.org/project/pdf_using_mpdf', extract in 'sites/all/modules', rename the folder as 'mpdf' and enabled the 'mpdf' module.
  • Download the 'MPDF' library from 'http://www.mpdf1.com/mpdf/index.php?page=Download', stored it in 'sites/all/libraries' and rename the folder as 'mpdf'.
  • Correct the folder permissions of all MPDF folder in 'sites/all/modules', 'sites/all/libraries', sometimes it will be read-only.
  • Add the permissions for the necessary users in 'people/permissions' using 'PDF using mPDF' option.
  • Configure 'PDF using mPDF settings' in 'admin/config/user-interface/mpdf' for designing and configuring the generating PDF files. Here, we can set 'Open PDF File in', 'Watermark Option', 'PDF Header & Footer Option' etc.

To check on various other module configurations in Drupal click here

After the above configuration,

  • I have created a page callback with supporting menus and functions to fetch data for PDF generation.
  • Then I used, pdf_using_mpdf_api(), with 2 parameters. First parameter for the data to display in PDF file and the second one for the name for the PDF file.

Please let us know if we can provide any further assistance.

References :