Convert HTML to PDF and Image on CentOS 5/6/7
wkhtmltopdf and also wkhtmltoimage are usually get series tools for you to give HTML directly into PDF and also different picture codecs.
wkhtmltopdf can put a number of physical objects in to the output file. A item can be a single webpage, a cover webpage, or a table of contents associated with items. This objects are usually placed into this output file in the order they are specified on the command line. Selections could be specified over a for each item time frame or perhaps in the world wide options region.
you can also download latest versions at wkhtmltopdf download list page.
Step 1: Install Dependencies
Install dependencies using following command:
# yum install xorg-x11-fonts-75dpi
Step 2: Download RPM package
You can download RPM packages according to your server requirement
For 32 bit
CentOS 5 # wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos5-i386.rpm CentOS 6 # wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-i386.rpm
For 64 bit
CentOS 5 # wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos5-amd64.rpm CentOS 6 # wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm CentOS 7 # wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm
Step 3:Install RPM package
After download RPM package, Now we can install it using rpm command:
# rpm -ivh wkhtmltox-0.12.2.1_linux-centos*
Step 4: Use wkhtmltopdf
# wkhtmltopdf http://www.techoism.com/odesk-javascript-test /usr/local/apache/odesk.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
# wkhtmltopdf toc http://www.techoism.com/odesk-javascript-test /usr/local/apache/odesk_toc.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
Step 5 Check PDF file
The Evince Document Viewer application for GNOME desktop environment. Evince is a record viewer equipped for showing numerous and single page archive organizations like PDF and Postscript. Now we can check PDF file, So for that we can install evince package first and check pdf file:
# yum install evince # evince /usr/local/apache/odesk_toc.pdf
Step 6: Convert HTML to Image
Create your HTML document that you want to turn into a image.
# wkhtmltoimage http://www.techoism.com/odesk-javascript-test /usr/local/apache/odesk.pdf