Skip to main content
Inspiring
September 11, 2009
Question

PDF manipulation with CF8

  • September 11, 2009
  • 1 reply
  • 737 views

I usually post questions here, but I wanted to post something cool about CF8 for a change...

I was trying to utilize our newly acquired CF8 for dynamically generating invoices from a flex program I wrote. Creating a form and filling in the fields was easy enough, but I needed something a bit more. I needed to be able to place formatted text on the page in places that didn't have fields. Essentially what I needed to do was a merge, but not the type that takes two 1 page PDFs and makes one 2 page PDF, but one that takes one PDF and lays it on top of another PDF on the same page. Well, low and behold, after searching the Internet getting clues from here and there (can't remember exactly where, but I'll give general credit out to whoever helped), I figured it out.

I can now take a template PDF form and fill it in with data from a query, place a HTML page over the top of that so I can use colors, images, whatever, then merge the whole thing together and deliver a flattened PDF document to the user. CF8 is turning out to be quite powerful!

The trick was creating a PDF document in memory out of HTML using absolutely positioned DIVs to place the text where I wanted it on the final PDF. Then use a PDF form, filled in from my query as a watermark above the HTML pdf. This watermark is set at full opacity, but the background is transparent, so it lays over the HTML page perfectly. When the whole thing is flattened, saved and loaded back into the browser, I have my completed form with HTML text positioned exactly where I want it in whatever font, color, style or any other HTML element I need. Even these HTML elements can be driven from the query data.

I know there are problems with this as the user could remove the watermark and the whole thing would be gone, but I couldn't figure out how to use an in memory PDF file as the watermark... (anybody know the answer to that one?)

Fun stuff!

Matt

    This topic has been closed for replies.

    1 reply

    Inspiring
    September 12, 2009

    Interesting approach!

    TransoniqHacker wrote:

    I know there are problems with this as the user could remove the watermark and the whole thing would be gone, but I couldn't figure out how to use an in memory PDF file as the watermark... (anybody know the answer to that one?)


    You mean cfpdf would not accept a pdf variable, it required a physical file? You could always use iText (java library used by cfdocument internally) if it is really needed..