Free PHP Libraries for Creating Professional Reports

February 19th, 2009 | Tags: , , , ,

When working on a couple of e-commerce web projects at work, I’ve found that being able to generate a report dynamically definitely wows a client.  Over time, I was able to find and try out a several PHP libraries from creating reports such as MS Excel files, PDFs and fancy charts.  Here I’ve compiled a list of some of the most reliable, and best of all, free, libraries I’ve found for PHP.

Create MS Excel Files

PEAR’s Spreadsheet_Excel_Writer: This library has been pretty much untouched, and maybe discontinued, since the end of 2006, and although there have been projects forked from Spreadsheet_Excel_Writer, I’ve still found this original to be the most reliable.  It does pretty much everything you’ll probably need it for.  I haven’t tried any real advanced Excel features, but for most things like using formulas, type and style formatting, etc., it’s enough.  It is a part of the PEAR framework, so you’ll need to have that install.  The only issue is that there are some issues with outputting Unicode strings.  There are patches that people have posted around the Internet that fixes it and lets you set a UTF-8 encoding properly.  I’ve used it and it works, but I do not remember the original source of the patch.

Create PDFs

TCPDF: This is probably the best free PDF generation library I’ve found on the Internet.  I’ve came upon it by accident while playing around with Joomla! CMS coding, and I was wow-ed by the number of features that this library supports.  I’ve found that several other popular CMS also use it for their PDF generation purposes.  One of the most interesting feature is the ability to create PDFs from HTML markup.  Although I haven’t personally tested how good the HTML to PDF rendering is, it does support inline CSS.  It also has ability to create some charts and support for CMYK colors, which might be useful for those in the printing industry.  Unicode text is fully supported also, but will increase output file size because of the large embedded font data.  The great thing is that this library is constantly updated.

FPDF: The FPDF library is a fairly simple library and not as extensive as TCPDF, but it has enough features to create a nice PDF document.

FPDI: Technically not a PDF generation library, it’s main use it to be able to import an existing PDF as a template for you to work with.  The library supports both TCPDF and FPDF.  Very useful if want to create a variable-data template where text can be dynamically added on top of a PDF template on demand.  I’m sure with enough work you can create your own web-to-print system with these tools, but there are better tools for that (but not free), such as PDFLib

Create Charts

FusionCharts Free: A free charting software with tons of possibilities in the types of graphs you can create.  The charts are Flash, but you don’t need to know Flash, and use any common programming language (not limited to PHP).  The documentation is very extensive and you can be on your way to generating fancy charts with animation in no time.

PHP/SWF Charts: Another Flash charting software with a lot of graph types.  However, there is a paid license for it and accesses additional features and removes one of the most irritating feature of the free chart: when you click on a chart it goes to the PHP/SWF Charts website.  (There are workarounds to preventing that though.)

With these sets of libraries you should be able to generate some pretty slick and professional reports on your commerce website without spending a dime on software!

Now if I can only find a free library that can create MS Word documents…

  1. December 6th, 2009 at 22:33
    Reply | Quote | #1

    Hi,
    I will like to suggest two more:

    For excel I found http://phpexcel.codeplex.com/.

    For Charting “JPGraph”.

    I am also looking free library for MS-Word document.

    If you find any please let me know.

    With Best Regards

  2. December 8th, 2009 at 23:04
    Reply | Quote | #2

    Shashank,

    Thanks for the link. PHPExcel sounds like a great library. I’ve came upon it before but haven’t gotten around to using it. However, the ability to read an Excel 2007 file functionality sounds like a huge plus compared to other libraries.

    I’ve tried looking for a free PHP library before for writing MS Word documents also without any luck. I’d also like to know if anyone finds one.

*