TecMint.com is a community driven Linux website. Our motto is to provide an effortless howto’s to our valuable readers.

You are also welcome to join our community and can be part of our team, contributing and submitting well written article on Linux. If you have any query, please contact us by email tecmint.com [at] gmail [dot] com or use our contact form.

Install Wkhtmltopdf (HTML Page To PDF Converter) in RHEL, CentOS, Fedora

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.
Install Wkhtmltopdf in Linux

Install Wkhtmltopdf (HTML to PDF Converter) in Linux


In this article we will show you how to install Wkhtmltopdf program under RHEL, CentOS and Fedora32-64 bit 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.

# yum install evince

Download Wkhtmltopdf Source File

Download wkhtmltopdf source files for your Linux architecture using Wget command, or you can also download latest versions at wkhtmltopdf download list page.

For RHEL/CentOS/Fedora 32-bit OS
# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2
For RHEL/CentOS/Fedora 64-bit OS
# wget https://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2

Install Wkhtmltopdf

Extract the files to a directory such as /opt, using following tar command.

## For RHEL/CentOS/Fedora 32-Bit OS ##
# tar -xvf wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2 -C /opt

## For RHEL/CentOS/Fedora 64-Bit OS ##
# tar -xvzf wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2 -C /opt

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

## For RHEL/CentOS/Fedora 32-Bit OS ##
# cd /opt
# mv wkhtmltopdf-i386 wkhtmltopdf
# mv wkhtmltopdf /usr/local/bin

## For RHEL/CentOS/Fedora 64-Bit OS ##
# cd /opt
# mv wkhtmltopdf-amd64 wkhtmltopdf
# mv wkhtmltopdf /usr/local/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 Remote HTML Page to PDF File

To convert any HTML web page to PDF, run the following example command. It will convert the given webpage to install-eclipse.pdf as as output to /opt directory.

# wkhtmltopdf http://www.tecmint.com/install-eclipse-classic-in-rhel-centos-fedora/ /opt/install-eclipse.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)
Done

View Generated PDF File

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

# file /opt/install-eclipse.pdf
Sample Output :
install-eclipse.pdf: PDF document, version 1.4

View Information of Generated PDF File

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

# pdfinfo /opt/install-eclipse.pdf
Sample Output :
Title:          Install Eclipse Classic 4.2.1 in RHEL/CentOS 6.3/5.6, Fedora 17-12
Creator:
Producer:       wkhtmltopdf
CreationDate:   Tue Oct  9 15:57:53 2012
Tagged:         no
Pages:          4
Encrypted:      no
Page size:      595 x 842 pts (A4)
File size:      355373 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 /opt/install-eclipse.pdf
Sample Screenshot :

Looks pretty nice under my CentOS 6.3 box.

Create PDF in Linux

View install-eclipse.pdf file in CentOS 6.3

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 http://www.tecmint.com/install-eclipse-classic-in-rhel-centos-fedora/ /opt/install-eclipse.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)
Done

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

# evince /opt/install-eclipse.pdf
Sample Screenshot :

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

Create TOC using Wkhtmltopdf

View TOC of install-eclipse.pdf file in CentOS 6.3

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

4 Responses

  1. 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”

  2. Kamran says:

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

Leave a Reply

Proudly designed by Tecmint.com.