Best HTML to PDF converter (WKHTMLTOPDF)

WKHTMLTOPDF (WebKit html to pdf converter) LIBRARY


1) wget
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

6) PHP
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.

  1. It is a primitive class for html to pdf conversion. But it has not been updated since 2 years.
  2. This class cannot handle pages properly.
  3. Configuration hassle.
  4. Images manipulation is not perfect.
  5. It takes a lot of memory and loading time.
  6. 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.


  1. Easy to configure.
  2. It can handle graphs.
  3. It supports PDF commands.
  4. It can convert html to pdf forms.
  5. CSS reading capability is superb.
  6. Html handling is much better than DOMPDF.
  7. Images manipulation is very good.
  8. Require understanding with the code.
  9. Loads fast as compared to DOMPDF.
  10. It does not require any other library or specs.
  11. For image manipulation it uses GD2 Lib


WKHTMLTOPDF Some sample commands

–disable-smart-shrinking //High quality PDF

-O Landscape //Orientation

--margin-left 0mm

--margin-right 0mm

--margin-top 27mm

--margin-bottom 12mm

--footer-html customFooter.html

--header-html customHeader.html

–header-spacing 30

--footer-spacing 5


1 Comment

  1. Oakley Sunglasses Sale

    Thanks very interesting blog!


Leave a Comment

Your email address will not be published. Required fields are marked *