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:

Today (and for the last few days) I am faced with a choice of PDF-generation libraries available in PHP.

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.

Related Posts

Users’ mail: configuring SMTP account to send mails with Doke0s

Note: as of 2010, BeezNest has moved away from supporting Dokeos and launched...

Can’t use function return value in write context

Did you ever develop some nice code, then simply wanted to check if...


Comments are closed.