23.8 C
Texas

How To Install wkhtmltopdf and wkhtmltoimage On Ubuntu 20.04

Today we are going to learn that how we can convert our web pages from html format to pdf or image format. For obtaining these results we’ll use the most famous command line tools wkhtmltopdf & wkhtmltoimage. They are Open Source Command line tools used for conversion processes from html to pdf and image respectively.Follow the guide to get started that how we can Install wkhtmltopdf & wkhtmltoimage on Ubuntu 20.04 Linux.

They both use the QT WebKit rendering engine to perform the actions.

By default, the versions available on Ubuntu are old for these tools. So, we have to Install them manually.

First of all we’ll download the tools from .deb package. Further these tools do not require a display so they are entirely headless.

Step 1: Update Your System

- Advertisement -

First of all update your system to have the latest updates installed.

sudo apt update -y

Step 2:Install wkhtmltopdf on Ubuntu 20.04

On Ubuntu 20.04:
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb

Output:

sabi@Ubuntu20:~$ sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb
[sudo] password for sabi:
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 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 0 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/sabi/wkhtmltox_0.12.6-1.focal_amd64.deb wkhtmltox amd64 1:0.12.6-1.focal [15.7 MB]
Get:2 http://pk.archive.ubuntu.com/ubuntu focal/universe amd64 xfonts-75dpi all 1:1.0.4+nmu1 [3,368 kB]
Fetched 3,368 kB in 3s (1,121 kB/s)
Selecting previously unselected package xfonts-75dpi.
(Reading database … 200571 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.1) …

Verify the installed version by typing.

sabi@Ubuntu20:~$ wkhtmltopdf --version
wkhtmltopdf 0.12.6 (with patched qt)
sabi@Ubuntu20:~$ wkhtmltoimage --version
wkhtmltoimage 0.12.6 (with patched qt)
Ubuntu 18.04:
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
sudo apt install ./wkhtmltox_0.12.6-1.bionic_amd64.deb
On Ubuntu 16.04:
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.xenial_amd64.deb
sudo apt install ./wkhtmltox_0.12.6-1.xenial_amd64.deb

Note:If you get error for the fonts try the following command.

sudo apt-get update -y
sudo apt-get install -y xfonts-75dpi

You can see the following results upon successful Installation

Step 3: How to Use wkhtmltopdf on Ubuntu 20.04

wkhtmltopdf  <webpage> <destination-pdf-file>

Look at the example:

wkhtmltopdf https://osradar.com osradar.pdf
Execution Output:

A pdf file will be created and you can view the contents once it finished by typing

file osradar.pdf

You can convert to image using the same syntax as:

wkhtmltoimage https://osradar.com osradar.png

Congratulations! You’ve learned how we can convert our web pages to pdf and Image format using wkhtmltopdf and wkhtmltoimage tool.

If you’ve any queries regarding this tutorial, feel free to ask!

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article