Installing Wkhtmltopdf On Ubuntu 20.04 LTS Step by Step

On this short guide, we will learn how to install Wkhtmltopdf on Ubuntu 20.04 LTS operating system. This tools have to run entirely “headless” and do not require a display or display service.

Introduction

As a developer or user, sometimes in some cases, we face the situation where we need a tools for rendering an HTML document to be a PDF file for easy reporting and subscriptions.

One of the most used for this purpose is Wkhtmltopdf. Wkhtmltopdf is an open source (LGPLv3) and much effective command-line shell utility that enables user to convert any given HTML (Web Page) to PDF document or an image (jpg, png, etc). Wkhtmltopdf is written in C++ programming language and distributed under GNU/GPL (General Public License). It uses Qt WebKit rendering engine. layout engine to convert HTML pages to PDF document without loosing the quality of the pages and do not require a display or display service. The latest stabel version of wkhtmltopdf is version 0.12.6, which was released on June 11, 2020.

Wkhtmltopdf Installation steps On Ubuntu 20.04 LTS are as follow :

  • Prerequisite
  • Download wkhtmltopdf
  • Installing wkhtmltopdf
  • Using wkhtmltopdf





Prerequisite

Before we are going to install wkhtmltopdf on Ubuntu 18.04 LTS, we have to prepare the environment first as mentioned below :

  • Ubuntu 18.04 LTS System
  • an ordinary account with sudo privilege
  • Sufficient disk space

We also need an updated repository on our system, for this purpose we will use command line :

$ sudo apt update

The output will be as shown below :

rapik@diginetapp01:~$ sudo apt update
Hit:1 http://repo.mysql.com/apt/ubuntu focal InRelease 
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease 
Hit:3 http://us.archive.ubuntu.com/ubuntu focal InRelease 
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
Building dependency tree 
Reading state information... Done
248 packages can be upgraded. Run 'apt list --upgradable' to see them.
rapik@diginetapp01:~$ sudo install apt wget
install: cannot stat 'apt': No such file or directory
rapik@diginetapp01:~$ sudo apt -y install wget
Reading package lists... Done
Building dependency tree 
Reading state information... Done
wget is already the newest version (1.20.3-1ubuntu1).
wget set to manually installed.
The following packages were automatically installed and are no longer required:
linux-headers-5.4.0-26 linux-headers-5.4.0-26-generic linux-image-5.4.0-26-generic
linux-modules-5.4.0-26-generic linux-modules-extra-5.4.0-26-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 248 not upgraded.

Download Wkhtmltopdf Source File

By using wget command line, we will download Wkhtmltopdf source file to our system. The command line will be :

$ wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb

The output will be shown below :

rapik@diginetapp01:~$ wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
--2020-10-22 23:54:02-- https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
Resolving github.com (github.com)... 192.30.255.112
Connecting to github.com (github.com)|192.30.255.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/131323182/10e1d800-ab93-11ea-862e-4f209c09ebf0?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201023%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201023T065404Z&X-Amz-Expires=300&X-Amz-Signature=502a17f092ad44cfda8be9db83226c23a638f711a22186cc672415d2c28cbaa1&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=131323182&response-content-disposition=attachment%3B%20filename%3Dwkhtmltox_0.12.6-1.focal_amd64.deb&response-content-type=application%2Foctet-stream [following]
--2020-10-22 23:54:04-- https://github-production-release-asset-2e65be.s3.amazonaws.com/131323182/10e1d800-ab93-11ea-862e-4f209c09ebf0?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201023%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201023T065404Z&X-Amz-Expires=300&X-Amz-Signature=502a17f092ad44cfda8be9db83226c23a638f711a22186cc672415d2c28cbaa1&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=131323182&response-content-disposition=attachment%3B%20filename%3Dwkhtmltox_0.12.6-1.focal_amd64.deb&response-content-type=application%2Foctet-stream
Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.217.105.244
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.217.105.244|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15721382 (15M) [application/octet-stream]
Saving to: ‘wkhtmltox_0.12.6-1.focal_amd64.deb’

wkhtmltox_0.12.6-1.focal_a 100%[=====================================>] 14.99M 582KB/s in 72s

2020-10-22 23:55:19 (213 KB/s) - ‘wkhtmltox_0.12.6-1.focal_amd64.deb’ saved [15721382/15721382]

Installing Wkhtmltopdf

On this case we will have wkhtmltox_0.12.6-1.focal_amd64.deb file on our system. Then we will install it by using this file. We will submit the command line :

$ sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb

The output will be as shown below :

rapik@diginetapp01:~$ sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb 
Reading package lists... Done
Building dependency tree 
Reading state information... Done
Note, selecting 'wkhtmltox' instead of './wkhtmltox_0.12.6-1.focal_amd64.deb'
The following packages were automatically installed and are no longer required:
linux-headers-5.4.0-26 linux-headers-5.4.0-26-generic linux-image-5.4.0-26-generic
linux-modules-5.4.0-26-generic linux-modules-extra-5.4.0-26-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
xfonts-75dpi
The following NEW packages will be installed:
wkhtmltox xfonts-75dpi
0 upgraded, 2 newly installed, 0 to remove and 248 not upgraded.
Need to get 3,368 kB/19.1 MB of archives.
After this operation, 144 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 /home/rapik/wkhtmltox_0.12.6-1.focal_amd64.deb wkhtmltox amd64 1:0.12.6-1.focal [15.7 MB]
Get:2 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1 [3,368 kB]
Fetched 3,368 kB in 3min 2s (18.5 kB/s) 
Selecting previously unselected package xfonts-75dpi.
(Reading database ... 217539 files and directories currently installed.)
Preparing to unpack .../xfonts-75dpi_1%3a1.0.4+nmu1_all.deb ...
Unpacking xfonts-75dpi (1:1.0.4+nmu1) ...
Selecting previously unselected package wkhtmltox.
Preparing to unpack .../wkhtmltox_0.12.6-1.focal_amd64.deb ...
Unpacking wkhtmltox (1:0.12.6-1.focal) ...
Setting up xfonts-75dpi (1:1.0.4+nmu1) ...
Setting up wkhtmltox (1:0.12.6-1.focal) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for fontconfig (2.13.1-2ubuntu3) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...

Using Wkthmltopdf

Wkhtmltopdf application can be used automatically triggered by any other applications such as Odoo and also can be used manually. Here’s the command line to use Wkhtmltopdf.

$ wkhtmltopdf <URL_article> <newdocument.pdf>

The example is as below :

rapik@diginetapp01:~$ wkhtmltopdf https://otodiginet.com/database/tools-database/how-to-install-oracle-sql-developer-on-ubuntu-18-04 install_oracle_developer_on_ubuntu.pdf
Loading pages (1/6)
Warning: A finished ResourceObject received a loading finished signal. This might be an indication of an iframe taking too long to load.
Warning: A finished ResourceObject received a loading progress signal. This might be an indication of an iframe taking too long to load.
Counting pages (2/6)
Resolving links (4/6) 
Loading headers and footers (5/6) 
Printing pages (6/6)
Done

Conclusion

On this short guidance, we have shown you how to install Wkhtmltopdf on Ubuntu 20.04 operating system and using it in generating a pdf article.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *