So you may have noticed I didn't post a new CFPDF post last night. Problem was - well, I ran into a few problems. I'd like to describe one of them now as I'm sure other people will run into this as well.

Consider the following simple code:

<cfdocument format="pdf" name="mydocument">

<cfloop index="x" from="1" to="15"> <p> lorem upsom doloras paris hilton is my hero loreum ipsom dsoio foom an to dht end of the world will anyone actually read this probably not but let me put more realtext in so it flows a bit nicely <cfloop index="y" from="1" to="#randRange(1,9)#">This sentence will appear a random amount of time.</cfloop> </p> </cfloop>

</cfdocument>

<cfcontent type="application/pdf" reset="true" variable="#mydocument#">

This code takes some random text and simply feeds it to a cfdocument tag. Nothing special, right? But if I decide to manipulate the PDF? I'll be covering page deleting in full later on, but for now, look at this slightly modified version:

<cfdocument format="pdf" name="mydocument">

<cfloop index="x" from="1" to="15"> <p> lorem upsom doloras paris hilton is my hero loreum ipsom dsoio foom an to dht end of the world will anyone actually read this probably not but let me put more realtext in so it flows a bit nicely <cfloop index="y" from="1" to="#randRange(1,9)#">This sentence will appear a random amount of time.</cfloop> </p> </cfloop>

</cfdocument>

<cfpdf action="deletepages" pages="1" source="mydocument" name="mydocument">

<cfcontent type="application/pdf" reset="true" variable="#mydocument#">

This example simply takes the PDF, removes page one, and then serves it up again. But when you run this, you will get:

coldfusion.pdf.PDFDocWrapper is not a supported variable type. The variable is expected to contain binary data.

So this kind of makes sense I guess. My initial variable was binary data. When I used CFPDF to manipulate it, ColdFusion converted it into a PDF variable (like images, PDFs are a native data type in ColdFusion), and when I tried to use it as binary data in cfcontent, it complained. Now I think it would be nice if cfcontent would give me a hand here and just deal with it, but luckily there is an easy work around - toBinary:

<cfdocument format="pdf" name="mydocument">

<cfloop index="x" from="1" to="15"> <p> lorem upsom doloras paris hilton is my hero loreum ipsom dsoio foom an to dht end of the world will anyone actually read this probably not but let me put more realtext in so it flows a bit nicely <cfloop index="y" from="1" to="#randRange(1,9)#">This sentence will appear a random amount of time.</cfloop> </p> </cfloop>

</cfdocument>

<cfpdf action="deletepages" pages=1 source="mydocument" name="mydocument">

<cfcontent type="application/pdf" reset="true" variable="#toBinary(mydocument)#">

The only change in this last version was to wrap my mydocument variable in a toBinary call.

Make sense? Anyone else get tripped up by this?

Edit - I am ashamed to admit I forgot to thank the person who pointed this out to me - Greg Oberlag. This whole entry is based on what he taught me.