Cuelogic Blog Icon
Cuelogic Career Icon
Home > Blog > Product Development > Web > Convert HTML to PDF using WKHTMLTOPDF

Convert HTML to PDF using WKHTMLTOPDF

devhtmlpdf

I was looking for solution to generate the PDF from dynamic HTML in last week. I was looking for easy way to generate the PDF without being affected with syntax and design.

While goggling I found the tool: WKHTMLTOPDF

This tool is converting HTML (CSS support) to PDF the same way you save a PDF from browser.

Here are the steps to install and integrate the tool.

First, install the webkit library on your server.

$ wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.8.3-static.tar.bz2

$ tar -jxvf wkhtmltopdf-0.8.3-static.tar.bz2

$ sudo aptitude install ia32-libs

Make symbolic link to tool in /usr/local/bin

$ sudo ln -s /full_path/WKHTMLTOPDF /usr/local/bin/WKHTMLTOPDF

Now we are ready to use.

Now try the following command to convert the google page into PDF:

$ wkhtmltopdf http://www.google.com example1.pdf

There are many options where you can generate the different size/types of PDF like A4, A2 etc

Here are few examples:

$ wkhtmltopdf http://www.google.com examplea1.pdf -s A4

$ wkhtmltopdf http://www.google.com examplea2.pdf -s A2

Download wkhtmltopdf – Convert html to pdf using webkit (qtwebkit) – Google Project Hosting

Simple shell utility to convert html to pdf using the webkit rendering engine, and qt. Searching the web, I have found several command line tools that allow you to convert a HTML-document to a PDF-document, however they all seem to use their own, and rather incomplete rendering engine, resulting in poor quality. Recently QT 4.4 was released with a WebKit widget (WebKit is the engine of Apples Safari, which is a fork of the KDE KHtml), and making a good tool became very easy. To use this software download the latest static release unpack it and run it like

via: code.google.com