Monthly Archives: December 2015

Generating Invoice PDFs

I need to generate PDF files for invoices. How hard can it be? My project is developed using PHP, so I first had a look at the available PDF libraries for PHP.

TCPDF

TCPDF is a project to generate PDF files from PHP. It is available since 2002 and is used in many projects. However, there are a few concerns:

  • The API is not object oriented, but uses one huge TCPDF class. It uses PHP constants for several configuration options and the API does not use constants, but strings.
  • Example: To create a new TCPDF object with the page format A4 and mm as units, you would use: new TCPDF(‘P’, ‘mm’, ‘A4’);
  • The biggest showstopper is that configuration for fonts takes place using PHP constants, which, once defined, cannot be changed. That means that it is very hard to integrate TCPDF into Symfony2.

ZendPDF

ZendPDF is the PDF class from the Zend Framework. I have looked at ZendPDF Version 2. Given the repository activity on GitHub, it seems that ZendPDF is not really maintained and documentation is completely missing.

phantomjs

PhantomJS is a headless web browser based on WebKit, which can also be used to render the output of a HTML page to a file. Unfortunately, phantomjs has a serious kerning problem as seen here: Example PDF. The exact same issue occurs using wkhtmltopdf.

LaTeX

LaTeX is…well…LaTeX. Either you have it or you love it. In my case, the lack of experience with LaTeX and struggling for 2 hours implementing a proper footer placed LaTeX on the bottom of the priority list.

Web-based services

I had a look at several web-based invoicing solutions, including Sage One and Freshbooks. Sage One didn’t support downloading of invoice PDFs via the API, and Freshbooks wasn’t able to produce invoices switchable date formats per invoice.

Conclusion

Right now, my best bet is probably using LaTeX. I might update this post at a later point