Which one of these is the best PDF-API for PHP?
- ApacheFOP
- dompdf
- FPDF
- html2ps
- mPDF
- PDFlib
- TCPDF
- wkhtmltopdf
- Zend_Pdf
personally i'd rather go with tcpdf which is an ehnanced and mantained version of fpdf.
From the mpdf site: "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.
This is just a quick review of how fPDF stands up against tcPDF in the area of performance at each libraries most basic functions.
SPEED TEST
17.0366 seconds to process 2000 PDF files using fPDF || 79.5982 seconds to process 2000 PDF files using tcPDF
FILE SIZE CHECK (in bytes)
788 fPDF || 1,860 tcPDF
The code used was as identical as possible and renders just a clean PDF file with no text. This is also using the latest version of each library as of June 22, 2011.
I found mpdf better than tcpdf in terms of html rendering. It can parse css styles much better and create pdf that look very similar to the original html.
mpdf even supports css things like border-radius and gradient etc.
I am surprised to see why mpdf is so less talked about when it comes to html to pdf.
Check out the examples here http://www.mpdf1.com/mpdf/index.php?page=Examples
I found it useful for designing invoices, receipts and simple prints etc. However the website itself says that pdfs generated from mpdf tend to be larger in size.
Try TCPDF. I find it the best so far.
For detailed tutorial on using the two most popular pdf generation classes: TCPDF and FPDF.. please follow this link: PHP: Easily create PDF on the fly with TCPDF and FPDF
Hope it helps.
Personally I prefer to use dompdf for simple PDF pages as it is very quick. you simply feed it an HTML source and it will generate the required page.
however for more complex designs i prefer the more classic pdflib which is available as a pecl for PHP. it has greater control over designs and allows you do do more complex designs like pixel-perfect forms.
http://sourceforge.net/projects/html2ps/, is the best if you need the css and 3c compatibily.
if you can install software on your server, i suggest you to use http://wkhtmltopdf.org/.
There is also a drupal module using wkhtmltopdf :)
PHP take many resources to convert html in pdf, imho, php is not the right language to do that (if you expect a large numbers of coversion or large files to convert)
The Zend Framework's Zend_Pdf is really good. It's on par with pdflib in terms of control of output and complexity and is more portable because its a pure php solution. That said, its slower and uses more memory than pdflib. Pecl modules are always more efficient than a php solution.
DOMPdf is the easiest way to make a pdf quickly. Like Mike said, feed it html and it outputs a pdf. Under the hood, it has the option to use either r&ospdf or pdflib as the rendering engine.
I personally generate XSL:FO from PHP and use Apache FOP to convert it to PDF. Not a PHP-native solution, not very efficient either, but it works well even if you need to generate PDF with very complex layouts.
精彩评论