Choosing a PHP PDF generation library for Chamilo

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…

FeatureFPDFeZPDFdompdf FPDITCPDF
LicensePublic domainPublic domainLGPLApache SLv2LGPL
Easy PDF generation?yesyes??
Create from HTMLnonoyesnopartial?
Recent activity??yesyes?
UTF-8 (or -16)?nounclearyes?yes
Requires PHP5??noyes?no
Requires PHP4??nono?no
Requires DOM?noyesnono
Requires PDFLib?nooptionalnono
Good doc?yesyesyesyes

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.


Related Posts

A series of short, good articles about PHP

I just realized, through Chris Shifflet’s twitter feed, that there is a website...

Detect syntax errors in multiple PHP files with xargs

With the Command Line Interpreter for PHP (most of the time called php-cli...

8 Comments

Comments are closed.

Quick Contact Form