2014 update: This article is outdated. To date, the library that matches most of the comparison elements below is mPDF. You can include it in your project using Composer: https://packagist.org/packages/mpdf/mpdf
Today (and for the last few days) I am faced with a choice of PDF-generation libraries available in PHP.
[digg=http://www.digg.com/programming/Choosing_a_PHP_PDF_generation_library_for_Dokeos]
The requirements are:
- GPLv2 or compatible
- possibility to generate PDF files (obviously) easily
- possibility to transform an HTML file into a PDF file easily
- recently developed or still active, with an active community and a possibility to contribute
- possibility to handle UTF-8
What it can do without being a problem:
- require PHP5
- require PHP's DOM extension
- require PHP's PDFlib extension
What it cannot do:
- require PHP4
- require anything else than PHP extensions (and the PHP files in the package) (to the exception of font files)
- have an unclear license
- have incomplete/unusable documentation
Now the possible libraries that do what I want are:
- FPDF
- eZPDF
- CPDF (from what I read it's the initial class on which eZPDF was developed, so can be ruled out safely as being too complex)
- dompdf
- FPDI (extension built on FPDF to use existing PDF documents as templates, but in itself seems quite useless in our case)
- TCPDF (extension built on FPDF)
- PDFlib (ruled out for too strict licensing reasons)
- PDF PHP (ruled out because it's just a wrapper for ezpdf)
- PHP PDF Lib (ruled out because no longer developed)
Let's analyse them all...
Feature |
FPDF |
eZPDF |
dompdf |
FPDI |
TCPDF |
License |
Public domain |
Public domain |
LGPL |
Apache SLv2 |
LGPL |
Easy PDF generation |
? |
yes |
yes |
? |
? |
Create from HTML |
no |
no |
yes |
no |
partial? |
Recent activity |
? |
? |
yes |
yes |
? |
UTF-8 (or -16)? |
no |
unclear |
yes |
? |
yes |
Requires PHP5? |
? |
no |
yes |
? |
no |
Requires PHP4? |
? |
no |
no |
? |
no |
Requires DOM |
? |
no |
yes |
no |
no |
Requires PDFLib |
? |
no |
optional |
no |
no |
Good doc |
? |
yes |
yes |
yes |
yes |
The result of all this is that two challengers remain in Dokeos' case: dompdf and TCPDF.
Considering the conversion from HTML to UTF-8 might be very important in the case of certificates, but that UTF-8 might become very important in the future, and that TCPDF includes UTF-8 handling as well as some HTML elements, I will first give a go to TCPDF and, if satisfying, I will keep to that.
Comments
[...] Choosing a PHP PDF generation library for Dokeos « Dokeos lead developer?s Weblog [...]
Nice post, I was just deciding which library was better, you just saved me a lot of time. Thank you!
I think the UTF-8 support for dompdf has been implemented since, so you might want to consider looking a bit more into this one if that's one of your criteria. Yes, I just checked and it is now supported (since version 0.5), so I'm updating my table.
What about Zend_Pdf?
I didn't know about it. Would you like to help me put it into the list? Do you know the answers to all the questions (or most of them)?
[...] 结果又查到一篇Choosing a PHP PDF generation library for Dokeos,说ezpdf根本、确实、100%就不支持utf-8编码,合着白折腾了。 [...]
Wonderful list there.. some I've never come across before, very useful, Thanks :)
thus a good solution at last!