CFDocument woes

As I sit here and struggle with seemingly random internet outages (one minute one page works, the next it doesn’t, but now the page that didn’t work before does, whee), I am mulling over what I was trying to accomplish yesterday, and what my task list today looks like. Yesterday’s project was to work on one of the invoicing systems for a project, which requires the use of CFDocument to create a PDF on the fly. Now I don’t know about you, but I thought that it was a genius thing that ColdFusion did by including this CFDocument tag. Unfortunately for me, it doesn’t work well enough. Up until we got our hands on CF MX 7, we used a nifty free Java-PDF library called iText (which I also believe is the basis for the pre CF 8 version of cfdocument). It worked nicely for what it was that we needed, a simple PDF created line by line, using Java objects to place things on the pdf. It was a little cumbersome for every day use, but it worked. Then we rejoiced with the ease with which we were going to be able to create PDFs (and flashpaper, but who’s heard of that aside from me?) using standard HTML and a few easy tags. Easy peasy. Only it wasn’t.

For anyone creating a basic ‘hello world’ pdf, cfdocument is genius. You need a whole of one tag, cfdocument. Wrap that around your html and you have instant pdf. What started as something simple, grows more complex with each thing we add. So for most PDFs, the document is actually created to be some sort of a report, which requires a header and a footer. The header probably contains a logo, maybe some text, and the footer has some text, maybe some page numbers. Ok, this is easy enough, within the cfdocument tags, we use <cfdocumentitem type=”header”></cfdocumentitem> and <cfdocumentitem type=”footer”></cfdocumentitem> to run the header and footer on all of the pages. Ok, well that went easily enough. So then we want to keep our document text together, grouped, since we want to keep one section starting at the top of the page. That’s fine too, we just wrap the grouped items in cfdocumentsection tags. Uh oh, we have a problem. Our logo image at the top is zoomed in at about 200% and half of our document text is being cut off by the header!?!? Well, thankfully the folks at Macromedia (at the time) sort of fixed the image blowup issue, but after many attempts to get it to work and finding that I could enclose my image in a CSS sized div, I tend to go that way anyway (and use ‘pt’ or ‘in’ instead of ‘px’ for everything unless you want a headache). The next problem was the overwriting of the document text (which Macromedia pretty much ignored as a problem, they said it was fixed in a patch, but clearly it was not). To solve this, I had to add margins to the cfdocumentsection tag, so that it would push the text down (even though the header and footer was supposed to do that). So this was all months ago (if not years).

Yesterday I was struggling with tables. In my invoice, I needed a table that would print out borders around the information, like an invoice would. The problem was, that it was doubling the borders, and looking quite unrefined. Now according to CSS standards, you could just use border-collapse:collapse; or border-spacing:0; but no, this will not work in cfdocument land. So after hours of struggle with it, I eventually came up with a less elegant solution. I set my table headings to have a background color the same as my borders, which does look nice and finished, and then I did this:
.tableClass {
width:100%;
border:none;
border-collapse:collapse;
border-spacing: 0;
border-width:0;
}
.tableClass th{
background-color: #CCCCCC;
border:none;
padding:2pt;
}
.tableClass td.tdLeft{
border-left: 1pt solid #CCCCCC;
border-bottom: 1pt solid #CCCCCC;
padding:2pt;
}
.tableClass td.tdRight {
text-align: right;
border-right: 1pt solid #CCCCCC;
border-left: 1pt solid #CCCCCC;
border-bottom: 1pt solid #CCCCCC;
padding:2pt;
}

It mostly works. I have found that the tr that contains the th still shows a little slice of background color, but it is definitely a step in the right direction. Since I don’t have weeks to play with it (nor time to redo in iText, and no chance of upgrading to 8 without having serious old code issues from other sites) I’m hoping the slice of color isn’t noticable in print format, that it’s only really there in my zoomed in picky self screen. I’ll probably take a few more minutes at it, maybe try a white border or something, but I have much more to do.