Generating PDFs from HTML

New method: puppeteer + cli wrapper

Puppeteer is the new best way to build PDFs from html. It is a headless chrome browser being maintained as an NPM package by the official Chromium development team. While wkhtmltopdf hasn’t been updated in a while and is lacking most newer browser features (notably flex layouts), puppeteer benefits from being kept current with the newest chromium releases. Previous efforts have all been by 3rd parties reverse-engineering and trying to keep up with browser engines, while this is the first effort that is a first-class supported effort by a browser engine team. It is exposed as a node API for doing a lot more than just turing pages into PDFs, and to that end I’ve built a simple cli wrapper for generating PDFs:

I’m trying to get the CLI buildable under habitat for easier distribution to servers, but in the meantime the CLI can installed via npm by using npm install -g puppeteer-cli (due to puppeteer#375 this must currently be done using npm install -g puppeteer-cli --unsafe-perm=true). Emergence will need to be updated to make use of a puppeteer print command if available instead of wkhtmltopdf

Old method

wkhtmltopdf is no longer being supported

  1. Download the latest stable binaries from
  2. Place in /usr/local/bin
  3. Ensure wkhtmltopdf and wkhtmltoimage are executable by all and owned by root

Here are the commands when installing version 0.12.4 on ubuntu 14.04:

tyler@sandbox02:~$ cd ~/
tyler@sandbox02:~$ wget
tyler@sandbox02:~$ tar xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz 
tyler@sandbox02:~$ sudo cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/
tyler@sandbox02:~$ wkhtmltopdf -V
wkhtmltopdf 0.12.4 (with patched qt)

As of 8/7/2017 the url in step 2 no longer works. An updated url can be found by looking at the wkhtmltopdf docs and using the link tied to your distribution.

This was tested successfully on Ubuntu 16.04.

@tyler I just renamed this thread and turned it into a wiki, posting some initial notes about the new game in town