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
- Open source and cross platform.
- Convert any HTML web pages to PDF files using WebKit engine.
- Options to add headers and footers
- Table of Content (TOC) generation option.
- Provides batch mode conversions.
- Support for PHP or Python via bindings to libwkhtmltox.
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 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.
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




Hi, I installed. No errors but when I run wkhtmltopdf http://google.com /opt/test.pdf
I get error “-bash: wkhtmltopdf: command not found”
If wkhtmltopdf is in your present working directory, you should run like.
I solved it, I run like this /usr/local/bin/wkhtmltopdf/wkhtmltopdf-amd64 http://google.com /opt/test.pdf
Ok, but now another problem, I cant run it from php. Please help me
Can you tell me , how I can add Tahoma font to generated pdf? or another font with utf-8 support (for characters üöğıəçşÜÖĞİƏÇŞ)