WKHTMLTOPDF (WebKit html to pdf converter) LIBRARY
INSTALLATION AND IMPLEMENTATION wkhtmltopdf in Linux
1) wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
2) tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
3) mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
4) chmod +x /usr/local/bin/wkhtmltopdf
5) Install dependencies via yum:
yum install fontconfig libXrender libXext ‘*fonts*’ openssl
|Note: NEW Updated version
sudo yum localinstall -y wkhtmltox-0.12.1_linux-centos6-amd64.rpm
i) $cmd = ‘/usr/local/bin/wkhtmltopdf “file1.html” “file2.html” “file3.html” “final.pdf” //Default PDF create
ii) $cmd = ‘/usr/local/bin/wkhtmltopdf -O Landscape “file1.html” “file2.html” “file3.html” “final.pdf” //Landscape
iii) $cmd = ‘/usr/local/bin/wkhtmltopdf -O Landscape –header-html “header.html” “file1.html” “file2.html” “file3.html” “final.pdf” //Landscape with header section, here header.html will have page number and top border after page.
7. Source and documentation
8. PDF Library Comparison details
DOMPDF : php class that wrap the html and build the pdf. Works good, customizable, based on pdflib, it will take CSS. Bad news: slow when the html is big or many complex.
- It is a primitive class for html to pdf conversion. But it has not been updated since 2 years.
- This class cannot handle pages properly.
- Configuration hassle.
- Images manipulation is not perfect.
- It takes a lot of memory and loading time.
- Easy to code.
HTML2PS: same of DOMPDF, but this one convert first in .ps (ghostscript), then, in whatever format we need (pdf, jpg, png). For me is little better then dompdf, but have the same speed problem.. oh, better compatibility with css.
Those two are php classes, but if we can install some software on the server, and access it throught passthru() or system(), give a look to these too:
wkhtmltopdf: based on webkit (safari’s wrapper), is really fast and powerfull.. seem like is the best one (atm) for convert on the fly html pages to pdf, taking only 2 seconds for a 3 pages xHTML document with CSS2. Is a recent project, anyway, the google.code page is often updated.
htmldoc : this one is a tank, it really never stop/crash.. the project seem death in the 2007, but anyway if we dont need css compatibility this can be nice for ya.
mPdf: “mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF, with a number of enhancements.”
mpdf is superior to FPDF for language handling and UTF-8 support. For CJK support it not only supports font embedding, but font subsetting (so your CJK PDFs are not oversized). TCPDF and FPDF have nothing on the UTF-8 and Font support of mpdf. It even comes with some open source fonts as of version 5.0.
- Easy to configure.
- It can handle graphs.
- It supports PDF commands.
- It can convert html to pdf forms.
- CSS reading capability is superb.
- Html handling is much better than DOMPDF.
- Images manipulation is very good.
- Require understanding with the code.
- Loads fast as compared to DOMPDF.
- It does not require any other library or specs.
- For image manipulation it uses GD2 Lib
WKHTMLTOPDF Some sample commands
–disable-smart-shrinking //High quality PDF
-O Landscape //Orientation