This document will show you how to get wkhtmltopdf working on Debian using KnpLabs Snappy. If you try and install from distribution you won’t get some of the latest features of wkhtmltopdf like {shell}–javascript-delay{/shell}. This guide will help you install the latest version {shell}0.11.0 rc1{/shell}. This guide assumes you have LAMP already installed and that you can run {shell}sudo{/shell}.

1. Installing dependencies

Before you install you will need to have X11, gcc and openssl installed.

3. Installing QT

Before you can compile wkhtmltopdf you need to have QT installed, again you have two options: You can install the QT from your distribution, this will be fast but your wkhtmltopdf build will not have all the features of the static build, or you can compile QT your self, this takes a long time but you will get all the features.

NOTE: I would suggest installing from distribution (3.b). I tried installing from source and it didn’t work.

Using KnpLabs Snappy

Here I will show you how to use KnpLabs Snappy. Snappy is a PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. It uses the excellent webkit-based wkhtmltopdf and wkhtmltoimage available on OSX, linux, windows.

Notes

In order for wkhtmltopdf to correctly print the chart, it is advised to remove any animations on hicharts.js objects. You will need to set the {javascript}animation{/javascript} property to false for both the {javascript}Chart{/javascript} object and the {javascript}plotOptions.series{/javascript} object.

Notes

Note the use of {php}javascript-delay{/php}:

PHP

1

$snappy->setOption('javascript-delay',500);

This will allow you to delay the printing of the pdf for a specified amout of time defined by ms. In this case the delay is set to {php}500ms{/php}. Also the {php}Content-Disposition{/php} is set to {php}inline{/php}. This will allow the pdf to show withing the browser window if the user has a pdf plugin installed. Supported browsers are Chrome and Safari. If the user does not have a supported browser they will be presented with a file download diaglog.