I wanted to express my thoughts here about PDF generation in PHP. Doing this by default is pretty easy. You download FPDF (or the library of your choice), you install it, configure it, and set it up. Then generally you just build your PDF. I recently ran across a few different classes that have claimed to take an xhtml/css page, and convert it to a PDF. I wanted to test it out. So I downloaded a PHP conversion class, tried it out, and it works perfectly. This is a strange euphoria. Not to mention, it pretty much supported all CSS. So the next time your stuck fighting with a manual PDF build, especially on those troublesome reports…try a converter instead. Might be as simple as trapping your HTML into a variable, passing it into a function and your done. The one that I used works with any good formatted HTML and most CSS styling options (just not floats).
Just to save you some time, I have done a little research and gotten some of the best options together for XHTML to PDF generation in a variety of different programming languages.
- PHP – Dom PDF
- Python – XHTML 2 PDF
- Ruby – Wicked PDF
- Perl – WKHTML To PDF
These languages had easy to find ones. There were a few languages I had trouble finding one for (ASP, and a few other languages).
If I find any more good ones for any major language, I will come back and list it here later on.
PDF generation technology has improved over the years since I wrote his blog post, so it’s possible to find a lot more information, ready-made scripts, and other things online.