We have been discussing simple browser-based options for PDF generation since the planning phase of the OCG project. While OCG's LaTeX-based render pipeline delivers nicely formatted and -linked documents, it does lack support for many content elements (tables, maps, media, most CSS). It is also complex (queues, custom caches, HTML to LaTeX conversion, custom image spidering / scaling), and thus expensive to maintain.
Simple browser-based rendering solutions promise a significantly lower cost, while also improving performance and content coverage. However, generally this comes at some cost to the quality of the print layout. Newer versions of PhantomJS and other tools have improved somewhat in this area, but there is still a gap.
## Option: [PhantomJS](http://phantomjs.org/)
PhantomJS 2 has been updated to a fairly recent `Blink` (Chrome) version. It is available in Debian & other distros. PDFs can be easily created using an invocation like this:
`phantomjs /usr/share/doc/phantomjs/examples/rasterize.js 'http://en.wikipedia.org/w/index.php?title=Barack_Obama&printable=yes' /dev/stdout a4 > /tmp/obama.pdf`
Latency is low, with about 2.3s for Obama on a laptop / cable connection. With performance in the single-digit seconds, there is no need for custom caching or state in the service, which greatly simplifies the infrastructure.
### Issues with PhantomJS 2
- **Links**: Due to limitation in the Qt5 PDF rendering backend, links are currently not clickable in the generated PDF. A [fix has landed in Qt5](https://github.com/ariya/phantomjs/issues/10196), so this issue should be resolved soon.
- **Page breaks**: Chrome & by extension PhantomJS 2 has relatively poor support for controlling page breaks using CSS (`break-before`, `break-after` etc). The most significant manifestation of this is that headings are often placed at the end of a preceding page, while the corresponding content follows on the next page. While ugly, this does not prevent access to the content.
## Option: [wkhtmltopdf](http://wkhtmltopdf.org/)
The stable version of the wkhtmltopdf tool is based on an older webkit version (equivalent to PhantomJS 1). Similar to PhantomJS, it has issues with Qt's hyperlink support. Some builds of wkhtmltopdf bundle a patched version of Qt, which allows wkhtmltopdf to generate (mostly) properly hyperlinked documents. Newer versions of wkhtmltopdf are expected to pick up the same Qt5 fixes as discussed for PhantomJS.
Overall, there seem to be few reasons to use wkhtmltopdf over phantomjs at this point.