Posted in ColdFusion | Posted on 07-12-2007 | 7,518 views
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:
2
3 <cfloop index="x" from="1" to="15">
4 <p>
5 lorem upsom doloras paris hilton is my hero loreum ipsom dsoio foom an to dht end of the world
6 will anyone actually read this probably not but let me put more realtext in so it flows a bit nicely
7 <cfloop index="y" from="1" to="#randRange(1,9)#">This sentence will appear a random amount of time.</cfloop>
8 </p>
9 </cfloop>
10
11</cfdocument>
12
13
14<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:
2
3 <cfloop index="x" from="1" to="15">
4 <p>
5 lorem upsom doloras paris hilton is my hero loreum ipsom dsoio foom an to dht end of the world
6 will anyone actually read this probably not but let me put more realtext in so it flows a bit nicely
7 <cfloop index="y" from="1" to="#randRange(1,9)#">This sentence will appear a random amount of time.</cfloop>
8 </p>
9 </cfloop>
10
11</cfdocument>
12
13
14<cfpdf action="deletepages" pages="1" source="mydocument" name="mydocument">
15
16<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:
2
3 <cfloop index="x" from="1" to="15">
4 <p>
5 lorem upsom doloras paris hilton is my hero loreum ipsom dsoio foom an to dht end of the world
6 will anyone actually read this probably not but let me put more realtext in so it flows a bit nicely
7 <cfloop index="y" from="1" to="#randRange(1,9)#">This sentence will appear a random amount of time.</cfloop>
8 </p>
9 </cfloop>
10
11</cfdocument>
12
13
14<cfpdf action="deletepages" pages=1 source="mydocument" name="mydocument">
15
16<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.


Its likely now that I won't get tripped up with this at all :)
Thanks!
Same general idea here...
[Add Comment] [Subscribe to Comments]