Install and enable the Printer, email and PDF versions module in the usual way. Learn more about installing Drupal modules. This module contains a number of 'sub-modules'; you should enable the print
and print_ui
modules, and one or more of the following modules.
- For PDF generation:
print_pdf
(required for any of the following),print_pdf_dompdf
,print_pdf_mpdf
,print_pdf_tcpdf
,print_pdf_wkhtmltopdf
. - For emailing print versions:
print_mail
. - For epubs:
print_epub
,print_epub_phpepub
.
Assign the necessary permissions at Administration > People > Permissions (admin/people/permissions
), under the heading of Printer-friendly pages, Printer-friendly pages UI and PDF version.
The print_pdf module requires the use of an external PDF generation tool. The currently supported tools are dompdf, TCPDF, wkhtmltopdf, and mPDF. Please note that any errors/bugs in those tools need to be reported and fixed by their maintainers. DO NOT report bugs in those tools in the print module's issue queue at Drupal.org.
Once you have downloaded a tool to the library path and you have enabled both the "PDF version" module and one of the "PDF library handler" modules, visit the settings page on your site at Administration › Configuration › User Interface › Printer, email and PDF versions › PDF (admin/config/user-interface/print/pdf
) and select the library path in the "PDF generation tool" setting.
Dompdf
The dompdf tool produces results that are more faithful to the HTML printer-friendly page.
- Download dompdf from https://github.com/dompdf/dompdf/releases/. The recommended version of this tool is 0.8.2 or newer. The "dompdf_0-8-2.zip" file contains the dependencies mentioned in the dompdf readme (this inclusion is a change from previous versions). Note that some earlier versions of dompdf have security vulnerabilities and incompatibilities with this module.
- Extract the contents of the downloaded package into your libraries directory (e.g. "sites/all/libraries").
- Grant write access to the lib/fonts directory for your webserver user.
- Review the recommendations for securing your dompdf installation.
- Check https://github.com/dompdf/dompdf/ for further information.
TCPDF
TCPDF support for CSS is considerably worse than Dompdf.
- Download TCPDF from http://sourceforge.net/projects/tcpdf/
- Extract the contents of the downloaded package into your libraries directory (e.g. "sites/all/libraries"). There is no need to modify the config/tcpdf_config.php file, as the module self-configures TCPDF.
- Check http://tcpdf.sourceforge.net/ for further information.
wkhtmltopdf
wkhtmltopdf launches a browser to generate the PDF, so the output is completely faithful to the contents of the page. However, it requires a LOT more memory and processing power, and you may need to compile/install it in your system to use it.
- Download wkhtmltopdf from https://wkhtmltopdf.org. You can choose to download the source and compile it or simply download the static binary, which doesn't require you to complile anything. New version of wkhtmltopdf located at https://wkhtmltopdf.org/downloads.html, it is already compiled as binary file
- Place the wkhtmltopdf executable into the your libraries directory (e.g. "sites/all/libraries"). You can also place a symbolic link to the executable. IMPORTANT: make sure you give executable permission such as 755 to wkhtmltopdf file
- You will need a running X Server or the virtual (headless) X framebuffer server: Xvfb. Place the Xvfb binary or a symbolic link to it in the print module directory (usually sites/all/modules/print/lib).
- Check if Drupal status reports any errors at: http://example.com/admin/reports/status
- If you see the error: "Unsupported wkhtmltopdf version", you probably need to install 3 depended libraries: e.g.
sudo aptitude install libxrender1 libfontconfig libXext-dev
- Check https://wkhtmltopdf.org/ for further information.
mPDF
mPDF has an extensive set of features which you can read about here. You might also be interested in reading the list of limitations.
- Download mPDF from https://github.com/mpdf/mpdf/releases/. The recommended version of this tool is 7.1.0 or newer.
- Extract the contents of the downloaded package into your libraries directory (e.g. "sites/all/libraries").
- If using mPDF 7.0 or later, run
composer install --no-dev
in the mpdf directory. - To be sure your environment is set up correctly, check the Requirements page. The PHP
mbstring
extension (includingmbregex
, which needs to be explicitly enabled in some environments) andgd
extension have to be loaded. - Check https://mpdf.github.io/ for further information.
Updating
When updating from a previous version, just remove the print directory and follow the instructions above. Make sure that you backup any customisation to the print.tpl.php and print.css files.
Robots
Even though it is possible to set per-page robots settings, the following can be placed in your robots.txt file after the User-agent line to prevent search engines from even asking for the page:
Disallow: /print/
Also, for updates from older versions (<=4.7.x-1.0 and <=5.x-1.2) which used node/nnn/print instead of print/nnn, the following lines can prevent requests from Google for the obsolete print URLs:
Disallow: /*/print$
Note that pattern matching in robots.txt is a Google extension (see http://www.google.com/support/webmasters/bin/answer.py?answer=40367 for more information).
Notes
Dompdf 0.5/0.6 compatibility issues are in http://drupal.org/node/552256.
Comments
wkhtmltopdf, no need for Xvfb if using static compiled binary
https://github.com/wkhtmltopdf/wkhtmltopdf
Put the executable in sites/all/libraries