In this guide, we will install wkhtmltopdf and wkhtmltoimage on Ubuntu / Debian Linux system. wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools used to render HTML into PDF and various image formats using the Qt WebKit rendering engine.

The versions of these tools available on Ubuntu / Debian Linux system are old. To get the latest wkhtmltopdf & wkhtmltoimage installed on Debian 10 / Ubuntu 18.04 Linux, you’ll need to manually download and install from the .deb package. These tools run entirely “headless” and do not require a display or display service.

Install wkhtmltopdf on Ubuntu 18.04 / Debian 10

Download the latest precompiled binary from the releases page. The latest release as of this article update is 0.12.5.

Install wkhtmltopdf on Ubuntu 18.04

sudo apt update
sudo apt -y install wget
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb
sudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb
sudo apt -f install

A successful installation output looks like this.

(Reading database … 172496 files and directories currently installed.)
Preparing to unpack wkhtmltox_0.12.5-1.bionic_amd64.deb …
Unpacking wkhtmltox (1:0.12.5-1.bionic) over (1:0.12.5-1.bionic) …
Setting up wkhtmltox (1:0.12.5-1.bionic) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …

Install wkhtmltopdf on Debian 10 / Debian 9

For Debian 9, run the commands.

sudo apt update
sudo apt -y install wget
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb
sudo dpkg -i wkhtmltox_0.12.5-1.stretch_amd64.deb
sudo apt -f install

Check the version of wkhtmltopdf and wkhtmltoimage to confirm installation was successful.

$ wkhtmltopdf --version
wkhtmltopdf 0.12.5 (with patched qt)

$ wkhtmltoimage --version
wkhtmltoimage 0.12.5 (with patched qt)

Using wkhtmltopdf on Ubuntu / Debian

For example, if you want to convert a web page as a PDF, use the command syntax:

$  wkhtmltopdf <webpage> <destination-pdf-file>

See below example.

wkhtmltopdf https://computingforgeeks.com computingforgeeks.pdf

Execution output:

A pdf file is created and you can open and view the contents.

$ file computingforgeeks.pdf 
computingforgeeks.pdf: PDF document, version 1.4

The similar syntax applies when converting to image.

$ wkhtmltoimage https://computingforgeeks.com computingforgeeks.png
Loading page (1/2)
QFont::setPixelSize: Pixel size <= 0 (0)=============>       ] 88%
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)==============>      ] 89%
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)===============>     ] 90%
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)===============>     ] 90%
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)===============>     ] 90%
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)===============>     ] 90%
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)===============>     ] 90%
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)===============>     ] 90%
QFont::setPixelSize: Pixel size <= 0 (0)=====================] 100%
QFont::setPixelSize: Pixel size <= 0 (0)
Rendering (2/2)                                                    
Done               

Check guides that uses wkhtmltopdf toolkit.

Install Odoo on Debian

Install Odoo on Ubuntu