Upon changing employers recently, I found that I had inherited a rat's nest of code used to generate project reports in PDF form on the fly. For each of our clients, there were numerous reports, all broken down into individual files with a staggering amount of code duplication and general redundancy. And I had the dubious honor of combing through these files in order to add columns to some tabular reports.
Generating PDFs is nothing like generating HTML. Everything you print to the page is pegged to coordinates on a grid rather than floating freely on the page within vague dimensional constraints. And so adding a column to an existing tabular report in PDF can be a nightmare.
After spending a frustrating morning crossing my eyes at thousands of lines of code while counting columns and calculating character widths and changing coordinates until the adjustments were finally correct, I decided to write a class that would handle all of this drudgery for me. What's more, I decided that the class should be useful for more than PDF output, and I built in support for HTML, XLS, and XML output as well.
The resulting code itself, while sufficient to handle the bulk of my needs, isn't quite ready for a public consumption yet, but some of the choices (and mistakes) I made while developing it might prove useful to others working on similar tasks. Accordingly, I offer here an account of how I brought an output class to life.