Drupal provide the functionality to generate PDF with few contributed modules using external libraries like dompdf, mPDF, TCPDF & wkhtmltopdf. We will be using ‘wkhtmltopdf’ to generate PDF using the page html. Wkhtmltopdf is open source (LGPLv3) command line tools to render HTML into PDF formats using the Qt Web-Kit rendering engine. These run entirely “headless” and do not require a display or display service. On this page we will explain how to provide the ability to generate PDF from your Drupal website using Linux machine.

Below are steps to be followed:

  1. Install print module on your Drupal website. Print module package have some sub modules with it. So we need enable few modules like ‘Printer-friendly pages’, ‘Printer-friendly pages UI’, ‘PDF Version’, ‘wkhtmltopdf library handler’.
  2. Install ‘wkhtmltopdf’ library on you Linux server with below steps and connect to your Drupal setup.

b. tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
c. sudo chmod -R 755 wkhtmltox
d. sudo mv wkhtmltox /usr/bin/
e. ln -s /usr/bin/wkhtmltox/bin/wkhtmltopdf /var/www/html/druapl/sites/all/libraries/wkhtmltopdf

  • Above steps will install wkhtmltopdf on your Linux machine and will create a symlink to the libraries directory. Now go to ‘/admin/config/user-interface/print/pdf’ and you will see ‘wkhtmltopdf’ as PDF generation tool. Select this tool and do appropriate configurations on that page and save configurations.
  • We can also manage wkhtmltopdf options from page ‘admin/config/user-interface/print/pdf/wkhtmltopdf’. These option helps to manage pdf content UI. You can get all wkhtmltopdf option from this page http://wkhtmltopdf.org/usage/wkhtmltopdf.txt .

Your setup is ready. Print module provide new display ‘print’ for all content types. We can enable this new display and manage the pdf content by managing the fields for this display.

Print module provides the feature to display a link on some specific positions on node view page (/node/[id]). We can manage the link position as per our comfort or we can directly access the url. New url for generating pdf for a node would be like ‘/printpdf/[nid]’.