Archives

19Feb/18
pdf-560x270

How To Install wkhtmltopdf In CentOS 6.5

Introduction

Taken from the site, wkhtmltopdf is an open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the QT Webkit rendering engine. These run entirely “headless” and do not require a display or display service. While this tool is quite cool to use, you have to install the dependencies of the said tool in order to get the stuff working.

And this is how to install wkhtmltopdf in CentOS 6.5

Audience

This blog intends for the people who, at least, have knowledge in CentOS.

Step 1: Preparation

Login to your CentOS machine. Make sure that you have root access. It is up to you on how you gain a root access by logging in directly as root user or do an su - command.

Step 2: Install Dependencies

Now that I mentioned it, there are two items needed in order to install the wkhtmltopdf:

  1. xorg-x11-fonts-Type1
  2. xorg-x11-fonts-75dpi

Install the two items with the following command

yum install -y xorg-x11-fonts-75dpi
yum install -y xorg-x11-fonts-Type1

Step 3: Install wkhtmltopdf

Next, download the wkhtmltopdf RPM file.

wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

Alternatively, if your computer is a 32-bit architecture, you may download the 32-bit version available in the Downloads page of the said site.

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

If fail then try in web browser and find new link in google search engine

wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-i386.rpm

After the file has been downloaded, run the command:

rpm -Uvh wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

And if for the 32-bit computers, run the command instead:

rpm -Uvh wkhtmltox-0.12.2.1_linux-centos6-i386.rpm

Step 4: Testing

And now for the test. Run the command (and make sure that the computer is accessible to the internet):

wkhtmltopdf http://www.google.com.ph google.pdf

During the generation, it will show something like this:

Loading pages (1/6)
Counting pages (2/6) 
Resolving links (4/6) 
Loading headers and footers (5/6) 
Printing pages (6/6)
Done

If the command generates the from the website to PDF file successfully, it is obvious that the wkhtmltopdf is working.

If the command generates from the website to PDF file successfully, it is obvious that the wkhtmltopdf is working.

 

Notes

When the latest version of wkhtmltopdf is available, change the version number accordingly.

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
DO NOT ADD in OUR Blog
Uses :- When we need to create PDF from browser and record greater than 10-20 K then browser may be hang or it take lot of time to load print preview (after that we click save to pdf button).
 
In current situation in dse final merit list have approximately for 67 thousands Records/rows. So browser unable to load print preview for 3000-4000 pages 
 
 
So alternative solution for this issue is :- wkhtmltopdf make pdf from directly from URL (i.e. from html pages)
 
for e.g. If HTML page is ready then it take 10-15 min to create PDF file.
 
[root@localhost html]# wkhtmltopdf -O Landscape –lowquality http://172.16.0.226/DTE_PORTAL/merit_display/final_report/html/final_merit_mh_candidate_dse17.phpSample_merit_pdf111.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
 
 
pdf ready