Back to Blog

How to Install wkhtmltopdf and wkhtmltoimage on Ubuntu 20.04, 18.04, and 16.04

K
Karan Goyal
--2 min read

A step-by-step guide on installing wkhtmltopdf and wkhtmltoimage on various Ubuntu versions

How to Install wkhtmltopdf and wkhtmltoimage on Ubuntu 20.04, 18.04, and 16.04

Introduction to wkhtmltopdf and wkhtmltoimage

wkhtmltopdf and wkhtmltoimage are open-source command-line tools used to convert HTML documents to PDF and image formats, respectively. These tools are particularly useful for generating reports, invoices, and other documents from web-based content. In this article, we will walk through the process of installing wkhtmltopdf and wkhtmltoimage on Ubuntu 20.04, 18.04, and 16.04.

Prerequisites

Before proceeding with the installation, ensure you have:

  • An Ubuntu system (20.04, 18.04, or 16.04)
  • Access to a terminal or command line
  • wget installed for downloading the necessary packages

Installing wkhtmltopdf and wkhtmltoimage

The installation process involves downloading the appropriate .deb package for your Ubuntu version and then installing it using apt.

For Ubuntu 20.04 and Later

  1. Download the .deb package using wget:
bash
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
  1. Install the downloaded package:
bash
sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb

For Ubuntu 18.04

  1. Download the .deb package:
bash
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
  1. Install the package:
bash
sudo apt install ./wkhtmltox_0.12.6-1.bionic_amd64.deb

For Ubuntu 16.04

  1. Download the .deb package:
bash
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.xenial_amd64.deb
  1. Install the package:
bash
sudo apt install ./wkhtmltox_0.12.6-1.xenial_amd64.deb

Verifying the Installation

After installation, you can verify that wkhtmltopdf is working correctly by checking its version:

bash
wkhtmltopdf --version

The output should be similar to:

plaintext
wkhtmltopdf 0.12.6 (with patched qt)

Testing wkhtmltopdf

To test wkhtmltopdf, you can convert a webpage to a PDF file:

bash
wkhtmltopdf https://google.com google.pdf

This command will generate a PDF file named 'google.pdf' in your current directory, containing the content of the Google homepage.

Conclusion

In this guide, we have successfully installed wkhtmltopdf and wkhtmltoimage on Ubuntu 20.04, 18.04, and 16.04. These tools are invaluable for converting web content into PDF and image formats, making them ideal for various applications such as report generation and document creation. If you have any questions or need further assistance, feel free to comment below.

Tags

#wkhtmltopdf#wkhtmltoimage#Ubuntu installation#PDF generation#command-line tools

Share this article

Comments (0)

Leave a Comment

0/2000

No comments yet. Be the first to share your thoughts!