On this article we will learn how to install wkhtmltodpf version 0.12.6 on Ubuntu 20.04 LTS. For installation on CentOS 7 you can see on How to Install and Using wkhtmltopdf on CentOS article.
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. These tools have to run entirely “headless” and do not require a display or display service.
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 On Ubuntu 20.04 LTS
wkhtmltopdf installation processes are consist of several steps, namely :
- Download wkhtmltopdf
- Install wkhtmltopdf
- Using wkhtmltopdf
1. Download wkhtmltopdf
Before deploying wkthmltopdf application, firstly we have to update our ubuntu system. Just submit the command line :
sudo apt update.
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.
Wkhtmltopdf version 0.12.26 has been already available and ready to be downloaded and install on our system to do so, we have to download it from its official website. For downloading it source, just issue the command line :
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)… 220.127.116.11 Connecting to github.com (github.com)|18.104.22.168|: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)… 22.214.171.124 Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|126.96.36.199|: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]
The source file has been downloaded and located on working directory, just list it for ensuring. We will find the
rapik@diginetapp01:~$ pwd /home/rapik rapik@diginetapp01:~$ ls -ltr total 15392 -rw-rw-r-- 1 rapik rapik 15721382 Jun 10 14:54 wkhtmltox_0.12.6-1.focal_amd64.deb
2. Install wkhtmltopdf
Install it as the command line 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) …
then verify it by querying its version, just submit command line:
rapik@diginetapp01:~$ wkhtmltopdf --version
3. Using wkhtmltopdf
On this section, we will use wkhtmltopdf to print the website from Ubuntu command line.
- working directory :
- web site to be printed :
- pdf file to be produced :
The command line is as follow :
wkhtmltopdf https://otodiginet.com/database/tools-database/how-to-install-oracle-sql-developer-on-ubuntu-18-04 install_oracle_developer_on_ubuntu.pdf
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
The pdf file has been created.
rapik@diginetapp01:~$ file install_oracle_developer_on_ubuntu.pdf install_oracle_developer_on_ubuntu.pdf: PDF document, version 1.4
By using the pdf reader application we could open it properly.
The wkhtmltopdf is useful tools for producing pdf file. On this article, we have through the installation it properly. I hope it will be useful for you. Stay at home, stay safe and happy weekend.