After lots of frustration and not-close-enough results with other HTML to PDF modules & libraries, I decided to make a Drupal implementation of something I know works extremely well.

IMHO: WkHtmlToPdf is just fantastic!

The Print module was way more than I needed and still would have required custom work for my requirements.

This is intended for module developers, nothing is usable from the front-end.

This module is a Drupal Library implementation for the PHPWkHtmlToPdf wrapper and as a result is extremely small because it uses WkHtmlToPdf to do the heavy work.

Requirements

WkHtmlToPdf Installed

You must have WkHtmlToPdf installed and working on the server before attempting to use this module.
See wkhtmltopdf.org for OS specific binaries.

Basically you'll want to download the latest release package and install it via your package manager.

Ubuntu example

Example: sudo dpkg -i wkhtmltox-0.12.2.1_linux-precise-amd64.deb

Installation

Reminder, you must have the OS specific packages of WkHtmlToPdf installed before using this module.

  1. Download and enable this module as you would any other Drupal module.
  2. Install library dependencies via drush make:
    drush make --no-core -y sites/all/modules/contrib/phpwkhtmltopdf/phpwkhtmltopdf.make
  3. Verify the "PHPWkHtmlToPdf " library version is displayed on your Status Page under:
    Reports > Status report.

Quick Start

The following example is an adaption from the official PhpWkHtmlToPdf docs located at: https://github.com/mikehaertl/phpwkhtmltopdf

if (($library = libraries_load('phpwkhtmltopdf')) && !empty($library['loaded'])) {
    $pdf = new WkHtmlToPdf();

    // Add a HTML file, a HTML string or a page from a URL
    $pdf->addPage('/home/joe/page.html');
    $pdf->addPage('<html>....</html>');
    $pdf->addPage('http://google.com');

    // Add a cover (same sources as above are possible)
    $pdf->addCover('mycover.html');

    // Save the PDF
    $pdf->saveAs('/tmp/new.pdf');

    // ... or send to client for inline display
    $pdf->send();

    // ... or send to client as file download
    $pdf->send('test.pdf');
}

Credits

A very special thanks goes out to the maintainers of WkHtmlToPDF and to authors of the PHP wrapper.

See WkHtmlTpPDF Contributors:
https://github.com/wkhtmltopdf/wkhtmltopdf/graphs/contributors

See PHP Wrapper Contributors:
https://github.com/mikehaertl/phpwkhtmltopdf/graphs/contributors

Project information

Releases