TCPDF: excelent library for generating PDF in PHP

The other day I was looking how to create PDF files in PHP.

The first thing that came to my mind was the PDFlib extension included in PHP since version 4. The problem with this library is that  I thought it was kind of low-level, and I didn’t had any idea on where to start.

In fact, the list of functions of PDFlib is quite big, and probably you can do about anything, but I did not want to be writing a hundred of lines to do a simple PDF, I just wanted to put a background image and write some lines in there.

Anyway, I decided to continue looking more information about this library and I end up finding a library called TCPDF, which is totally free, and seemed a lot more complete and simple. I really don’t know if it’s better or not than the PDFlib, but at least TCPDF has lots of examples. There are super-simple examples of about any aspect of the PDF, so doing your first PDF is a matter of copy-pasting from several examples. Really easy!

The truth is, that I did my FIRST prototype in about 15 minutes. Not bad at all. With this TCPDF library you can generate the PDF as if it was like a HTML file. You can pass the text using HTML tags (even CSS), and then the library internally converts that to the PDF, so you don’t have to think much about generating the PDF.

The only “problem” I see with this library is that the size of the zip file you have to download is around 10MB, which are around 16 MB once uncompressed. Anyway, almost all the size of the library comes from several fonts it includes, documentation and examples. If you remove the documentation and you keep only those fonts you are going to use, this library could be minified to 1 MB only.  Although for web development I think it does not worth to make it smaller. The size does not matter.

For more information about this library you can take a look at www.tcpdf.org

Trackback URL

, ,

Comments are closed.