The wkhtmltopdf
and wkhtmltoimage
are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These tools run entirely headless and don’t require a graphical user interface.
In this article, I will discuss how to install wkhtmltopdf
and wkhtmltoimage
in Ubuntu Linux.
Prerequisites
To follow this guide you need to have the following –
- A system running Ubuntu or a Ubuntu-based Linux distribution
- Access to a user account with sudo permissions
Installing wkhtmltopdf & wkhtmltoimage in Ubuntu
To install wkhtmltopdf
and wkhtmltoimage
in a Ubuntu system, you need to follow the given steps.
First, go to its official download page and click on the given link to download the precompiled debian package.
Alternatively, you can copy the downloading link and use the wget command to download it from your terminal –
For Ubuntu 20.04 LTS
Use the following command to download the deb package –
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
Once the downloading is completed move to the location where the file is downloaded and use the following command to install it on your system –
sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb
For Ubuntu 18.04 LTS
Use the following command to download the deb package for Ubuntu 18.04 LTS –
https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
Once the downloading is completed, use the following command to install it on your system –
sudo apt install ./wkhtmltox_0.12.6-1.bionic_amd64.deb
Now you can verify the installation by using the given command –
wkhtmltopdf --version
wkhtmltoimage --version
How to use wkhtmltopdf in Ubuntu
The wkhtmltopdf
and wkhtmltoimage
tools are able to put several objects into the output file, an object is either a single webpage, a cover webpage, or a table of contents.
The syntax of using wkhtmltopdf
command is given below –
wkhtmltopdf [source_file] [destination_file.pdf]
Example –
wkhtmltopdf google.com google.pdf
The syntax of how to use wkhtmltoimage
command is given below.
wkhtmltoimage [source_file] [destination_file.imageformat]
Example –
wkhtmltoimage google.com google.jpg
Both the files google.pdf and google.jpg that you have created will be saved in your home directory. You can open them using pdf viewer and image viewer tools.
Conclusion
I hope now you installed and are able to use wkhtmltopdf
and wkhtmltoimage
on your Ubuntu system Now if you have a query then write us in the comments below.