Thursday, April 25, 2013

Convert HTML + CSS to PDF with PHP?

How to Convert HTML + CSS to PDF with PHP ? 




Days ago.was searching for a solution for conveting html to pdf, was having have an HTML (not XHTML) document that renders fine in Firefox 3 and IE 7. It uses fairly basic CSS to style it and renders fine in HTML. i got many extraordinary tools / plugins for this matter, here i am sharing with  you.





 


PrinceXML.
It's definitely the best HTML/CSS to PDF converter out there, although it's not free (But  your programming is not free either, so if it saves you 10 hours of work, you're home free.)


 

WKHTMLTOPDF
Have a look at WKHTMLTOPDF . It is open source, based on webkit and free.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.

 

mPDF 
A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support.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.


DocRaptor
You can create a PDF or Excel file using the sample code we've provided, or by submitting custom HTML. Everything created here is done in test mode. If you want to create real documents,

 

TCPDF
It has some HTML to PDF functionality that might be enough for what you need. It's also free! it's support is for rendering html is rather limited, you might want to read this: tcpdf.
this is an ehnanced and mantained version of fpdf. Main Features of tpdf and it is also having less execution time with great output. For detailed tutorial on using the two most popular pdf generation classes: TCPDF and FPDF.. please follow this link

 

DOMPDF 
php class that wrap the html and build the pdf. Works good, customizable (if you know php), based on pdflib, if i remember right it takes even some CSS. Bad news: slow when the html is big or many complex.

HTML2PS 

same of DOMPDF, but this one convert first in .ps (ghostscript), then, in whatever format you 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 you can install some software on the server, and access it throught passthru() or system(), give a look to these too:

 

htmldoc 
this one is a tank, it really never stop/crash.. the project seem death in the 2007, but anyway if you dont need css compatibility this can be nice for you.


Hope you have enjoyed to read this post,
let me know if you have more suitable suggestions.

you might be more interested in PHP, CSS, html, PDF


Good Day [/ Night] ! Happy Google + ing !

:D

2 comments:

  1. This will come in handy, thanks!

    ReplyDelete
  2. You could use an API service like http://www.htm2pdf.co.uk - it offers an API in PHP or even a full flex SDK that not only converts to PDF, but also adds a lot of extra things like encryption, watermarking, stationary, merging etc.

    ReplyDelete

Any Questions or Suggestions ?

About

Professional & Experienced Freelance Developer From India, Technologist, Software Engineer, internet marketer and Open Sources Developer with experience in Finance, Telecoms and the Media. Contact Me for freelancing projects.

Enter your email address:

Delivered by FeedBurner