Generate PDF with PHP: FPDF, TCPDF, DOMPDF, ezPDF, FPDI and HTML2PDF

There are useful open source tools and libraries for generating images of various formats, csv(comma separated values), doc/docx and xls. Today, we are going to evaluate the options for PDF generation. Let’s have a look at some of the options available for generating PDF.

  1. FPDF: It is a simple class for generating PDF from pure PHP without using any extension like PDFlib library. And “F” in FPDF stands for “Free”. FPDF requires no special PHP extensions. Though, Zlib and GD extensions are to be enabled to support compression and GIF support respectively. It works with PHP 4 (at least 4.3.10) and PHP 5. The tutorials, download and demos are available at the project site http://www.fpdf.org/
  2. eZPDF: If you can’t control the PHP extensions, ezPDF is the class for you. It is another open source PDF generation class which generates PDF on the fly without requiring any special extensions at all. The performance is quite good but the features are slightly limited for complex outputs. Though, it is an excellent tool for generating simple PDF files. For details and documentation, you may refer the project site http://www.ros.co.nz/pdf/
  3. DOMPDF: It is a PHP5 (PHP 5.3 recommended) based PDF generation library and renders PDF primarily with PDFlib or with bundled and enhanced version of CezPDF class of R&OS . It is a feature rich library and supports almost all the HTML elements and styling attributes. Using with PDFlib, you will be required to download and enable PECL extension of PDFlib . The Mbstring is also required for the library to work. For further reading, refer to DOMPDF project home ; the code is hosted at Google Code .
  4. FPDI: It is an extension built on FPDF. It is essentially a collection of PHP classes for reading existing PDF files and generates new PDF files from the existing files. The existing PDF files are used as templates to generate new files. It doesn’t require any additional library or PHP extension. The details are available at the FPDI Project Home .
  5. TCPDF: It is another extension built on FPDF. It extends the features provided by FPDF to provide even more options for generation of complex PDF structures. Other than almost complete HTML support, it also supports Javascript, digital signatures, barcodes and much more. For further reading, download, examples and documentation, please refer to the Project Homepage .
  6. PDFlib: For those who are keen on buying expensive licenses, PDFlib is the PDF generation library. Working on Open source technologies, I don’t prefer paid options. The details can be read at the project home .
  7. HTML2PDF: HTML2FPDF is a PHP Class library that uses the FPDF class library to convert HTML files to PDF files. HTML2PDF library is a collection of three classes namely PDF, HTML2FPDF and FPDF. The FPDF class of HTML2PDF is basically a modified version of original FPDF class. These classes are inherited classes with PDF class extending HTML2FPDF class, which in turn extends the FPDF class.

Then, there is PDF PHP , which is just a wrapper of ezPDF. And, PHP PDF Lib, which is no longer maintained. Zend has its own PDF library included in Zend framework.

The verdict is in favor of DOMPDF, when you are able to control the PHP extensions. And definitely, TCPDF when you are not sure about installed extensions and you can add/modify them. Besides being stable and feature rich, this is another reason why TCPDF is most preferred choice.

 

Source:php.refulz

Comments
One Response to “Generate PDF with PHP: FPDF, TCPDF, DOMPDF, ezPDF, FPDI and HTML2PDF”
  1. Brady Urquidez says:

    I simply want to say I’m very new to blogging and honestly savored this web page. Most likely I’m going to bookmark your blog . You surely come with superb articles. Thanks a lot for sharing your website page.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.