Wkhtmltopdf – A Smart Tool to Convert Website HTML Page to PDF in Linux

Wkhtmltopdf is an open source simple 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 WebKit rendering layout engine to convert HTML pages to PDF document without loosing the quality of the pages. Its is really very useful and trustworthy solution for creating and storing snapshots of web pages in real-time.

Wkhtmltopdf Features

  1. Open source and cross platform.
  2. Convert any HTML web pages to PDF files using WebKit engine.
  3. Options to add headers and footers
  4. Table of Content (TOC) generation option.
  5. Provides batch mode conversions.
  6. Support for PHP or Python via bindings to libwkhtmltox.

In this article we will show you how to install Wkhtmltopdf program under Linux systems using source tarball files.

Install Evince (PDF Viewer)

Let’s install evince (a PDF reader) program for viewing PDF files in Linux systems.

$ sudo yum install evince             [RHEL/CentOS and Fedora]
$ sudo dnf install evince             [On Fedora 22+ versions]
$ sudo apt-get install evince         [On Debian/Ubuntu systems]

Download Wkhtmltopdf Source File

Download wkhtmltopdf source files for your Linux architecture using Wget command, or you can also download latest versions (current stable series is 0.12.4) at wkhtmltopdf download page.

On 64-bit Linux OS
$ wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
On 32-bit Linux OS
$ wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-i386.tar.xz

Install Wkhtmltopdf in Linux

Extract the files to a current working directory using following tar command.

------ On 64-bit Linux OS ------
$ sudo tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz 

------ On 32-bit Linux OS ------
$ sudo tar -xvzf wkhtmltox-0.12.4_linux-generic-i386.tar.xz 

Install the wkhtmltopdf under /usr/bin directory for easy execution of program from any path.

$ sudo cp wkhtmltox/bin/wkhtmltopdf /usr/bin/

How to Use Wkhtmltopdf?

Here we will see how to covert remote HTML pages to PDF files, verify information, view created files using evince program from the GNOME Desktop.

Convert Website HTML Page to PDF File

To convert any website HTML web page to PDF, run the following example command. It will convert the given webpage to 10-Sudo-Configurations.pdf in current working directory.

# wkhtmltopdf https://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/ 10-Sudo-Configurations.pdf
Sample Output :
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)

View Generated PDF File

To verify that the file is created, use the following command.

$ file 10-Sudo-Configurations.pdf
Sample Output :
10-Sudo-Configurations.pdf: PDF document, version 1.4

View Information of Generated PDF File

To view the information of generated file, issue the following command.

$ pdfinfo 10-Sudo-Configurations.pdf
Sample Output :
Title:          10 Useful Sudoers Configurations for Setting 'sudo' in Linux
Creator:        wkhtmltopdf 0.12.4
Producer:       Qt 4.8.7
CreationDate:   Sat Jan 28 13:02:58 2017
Tagged:         no
UserProperties: no
Suspects:       no
Form:           none
JavaScript:     no
Pages:          13
Encrypted:      no
Page size:      595 x 842 pts (A4)
Page rot:       0
File size:      697827 bytes
Optimized:      no
PDF version:    1.4

View Created PDF File

Take a look at the newly created PDF file using evince program from the desktop.

$ evince 10-Sudo-Configurations.pdf
Sample Screenshot :

Looks pretty nice under my Linux Mint 17 box.

View Website Page in PDF

View Website Page in PDF

Create TOC (Table Of Content) of a Page to PDF

To create a table of content for a PDF file, use the option as toc.

$ wkhtmltopdf toc https://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/ 10-Sudo-Configurations.pdf
Sample Output :
Loading pages (1/6)
Counting pages (2/6)
Loading TOC (3/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)

To check the TOC for the created file, again use evince program.

$ evince 10-Sudo-Configurations.pdf
Sample Screenshot :

Take a look at the picture below. it looks even more better than the above.

Create Website Page to Table of Contents in PDF

Create Website Page to Table of Contents in PDF

Wkhtmltopdf Options and Usage

For Wkhtmltopdf more usage and options, use the following help command. It will display list of all available options that you can use with it.

$ wkhtmltopdf --help

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide
The Complete Linux System Administrator Bundle
Become an Ethical Hacker Bonus Bundle

You may also like...

41 Responses

  1. cho says:

    how can I install this tool in my Solaris-x86 environment ??

  2. cho says:

    how can I install this tool in my Solaris-x86 environment ??
    I really want to know how to download and install in solaris OS.

  3. Mohan says:

    Hi Ravi,

    Is it possible to have our TOC in second page of our PDF during PDF generation using Wkhtmltopdf?? Please do reply asap..

    Thanks in advance :)

  4. Mike says:

    tar needs -j argument for bz2 files, not -z which is for gzip

  5. Anthony says:

    Good article, but it should be symlinked to /usr/bin to run from anywhere, also no one has yet thought to rename it to something shorter ?

  6. ganesh says:


    I am PHP developer. I have installed wkhtmltopdf in my application. I have one chart which is working fine in browser as html. But when I converts this to pdf via wkhtmltopdf it does not display. I searched on google but I didn’t find any solution.


  7. Hi

    I’ve used wkhtmltopdf on linux, mac and windows. Works great.
    Has anyone tried to install it on z/OS (zLinux probably) to be used from a batch environment called from JCL ?

  8. Ram says:

    Great work… Thanks for the detailed info.

  9. Kamran says:

    Can you tell me , how I can add Tahoma font to generated pdf? or another font with utf-8 support (for characters üöğıəçşÜÖĞİƏÇŞ)

  10. Kamran says:

    Hi, I installed. No errors but when I run wkhtmltopdf http://google.com /opt/test.pdf
    I get error “-bash: wkhtmltopdf: command not found”

Leave a Reply to Ravi Saive Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.