Rectangle 27 1

Convert HTML + CSS to PDF with PHP?


There's a tutorial on Zend's devzone on generating pdf from php (part 1, part 2) without any external libraries. I never implemented this sort of solution, but since it's all php, you might find it more flexible to implement and debug.

Note
Rectangle 27 1

Convert HTML + CSS to PDF with PHP?


If you have access to the command line it's possible to use PhantomJS to create the PDF from an URL (remote or local).

Note
Rectangle 27 1

Convert HTML + CSS to PDF with PHP?


I strongly recommend using tidy library as HTML pretty formatter before sending anything to TCPDF.

TCPDF works fine, no dependencies, is free and constantly bugfixed. It has reasonable speed if supplied HTML/CSS contents is well formated. I normally generate from 50 - 300 kB of HTML input (including CSS) and get PDF output within 1-3 secs with 10 - 15 PDF pages.

Note
Rectangle 27 1

Convert HTML + CSS to PDF with PHP?


Darryl Hein's mention above of TCPDF (http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf) is likely a great idea. Nicola Asuni's code is pretty handy and powerful. The only killer is if you ever plan on merging PDF files with your generated PDF it doesn't have those features. You would have to create the PDF and then merge it using something like PDFTK by Sid Steward (www.pdflabs.com/tools/pdftk-the-pdf-toolkit/).

Note
Rectangle 27 1

Convert HTML + CSS to PDF with PHP?


Flying Saucer takes XML or XHTML and applies CSS 2.1-compliant stylesheets to it, in order to render to PDF

It is usable from PHP via system() or a similar call. Although it requires XML well-formedness of the input.

not PHP, but a Java library, which does the thing:

Note
Rectangle 27 1

Convert HTML + CSS to PDF with PHP?


Flying Saucer takes XML or XHTML and applies CSS 2.1-compliant stylesheets to it, in order to render to PDF

It is usable from PHP via system() or a similar call. Although it requires XML well-formedness of the input.

not PHP, but a Java library, which does the thing:

Note
Rectangle 27 0

Convert HTML + CSS to PDF with PHP?


I've tried a lot of different libraries for PHP. All the listed I've tried. In my opinion TCPDF library is the best compromise performance/usability. It's very simply to install and use, also good performance in small medium application. If you need high performance and very big PDF document, use Zend_PDF module, but get ready to coding hard!

I've tried a lot of different libraries for PHP. All the listed I've tried. In my opinion TCPDF library is the best compromise performance/usability. It's very simply to install and use, also good performance in small medium application. If you need high performance and very big PDF document, use Zend_PDF module, but get ready to coding hard!

Note
Rectangle 27 0

Convert HTML + CSS to PDF with PHP?


Flying Saucer takes XML or XHTML and applies CSS 2.1-compliant stylesheets to it, in order to render to PDF

It is usable from PHP via system() or a similar call. Although it requires XML well-formedness of the input.

not PHP, but a Java library, which does the thing:

Note
Rectangle 27 0

Convert HTML + CSS to PDF with PHP?


I've tried a lot of different libraries for PHP. All the listed I've tried. In my opinion TCPDF library is the best compromise performance/usability. It's very simply to install and use, also good performance in small medium application. If you need high performance and very big PDF document, use Zend_PDF module, but get ready to coding hard!

Note
Rectangle 27 0

Convert HTML + CSS to PDF with PHP?


I've tried a lot of different libraries for PHP. All the listed I've tried. In my opinion TCPDF library is the best compromise performance/usability. It's very simply to install and use, also good performance in small medium application. If you need high performance and very big PDF document, use Zend_PDF module, but get ready to coding hard!

Note