CFDocument pdf generation broke after CF8 upgrade

Posted At : January 11, 2008 8:24 AM | Posted By : Dave
Related Categories: ColdFusion

I just did an upgrade to a system a couple days ago from CF7 to CF8. I received a report from users that a section of the system that generates pdf reports was breaking. I found this strange since this section of the system is used daily and we have not touched the code in over a year. I figured at this point that the upgrade had something to do with it. After some investigating I was able to figure out that it was in fact a CF8 specific issue. The code for the pdf generation worked in CF7 but breaks in CF8.

This is the error we were getting. The error itself it kinda odd because the code it shows does not contain the undefined var displayed in the error.

An exception occurred when performing document processing.
The cause of this exception was that: coldfusion.document.spi.DocumentExportException: java.lang.RuntimeException: Variable ID is undefined..

The error occurred in E:\www\code\report\index.cfm: line 735
Called from E:\www\code\report\index.cfm: line 47
Called from E:\www\code\report\index.cfm: line 735
Called from E:\www\code\report\index.cfm: line 47

733 :       </TR>
734 :       <TR HEIGHT="14">
735 :             <TD ALIGN="CENTER"><BR><IMG SRC="http://localhost/images/samples/#DIAGRAM2#"></TD>
736 :       </TR>
737 :       </CFIF>

Here is the code that was causing the error. This is not the exact code as I can not post it but it still has the necessary parts to effectively display the issue.

<CFDOCUMENT FORMAT="PDF" SCALE="100">

<CFOUTPUT QUERY="items">

<CFDOCUMENTITEM TYPE="FOOTER">
<table align="CENTER" width="100%" border="0" cellpadding="0" cellspacing="0">
   <tr height="4">
      <td height="4" colspan="3" bgcolor="F2F2F2"></td>
   </tr>
   <tr>
      <td align="left" width="10%"><font size="-3" >#dateFormat(now(), "mm/dd/yyyy")#</font></td>
      <td align="CENTER" width="80%"><font size="-3" >Project: (#id#) #title#</font></td>
      <td align="right" width="10%"><font size="-3" >Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</font></td>
   </tr>
   <tr height="4">
      <td height="4" colspan="3" bgcolor="F2F2F2"></td>
   </tr>
</table>
</CFDOCUMENTITEM>
<!--- BODY OMITTED --->
</CFOUTPUT>

</CFDOCUMENT>

The actual error was coming from this line of code:

<td align="CENTER" width="80%"><font size="-3" >Project: (#id#) #title#</font></td>

I could not quite understand why this would cause an error. I verified, via cfdump, that the data was coming out of the query accurately. Also, since I had a query attribute on the cfoutput the vars did not need to be scoped with the query name.

So, taking a shot in the dark I added the query name to the id and title vars. This fixed the issue and the pdf was generated.

I did even more digging after that and discovered that I only needed to scope them with the query name when inside cfdocumentitem. I was able to output the data just fine in the body unscoped.

Here is what the fixed code looks like. Just something else to look out for when doing an upgrade.

<td align="CENTER" width="80%"><font size="-3" >Project: (#items.id#) #items.title#</font></td>

till next time,

--Dave

Comments
Make sure to include the HotFix for CF8. It's filled with fixes for cfdocument.
# Posted By david buhler | 1/11/08 9:36 AM
CF 8 hot fix 2 is installed on the server but it has no effect on this issue.

--Dave
# Posted By Dave Ferguson | 1/11/08 10:04 AM
I get an error also with CFDOCUMENT that worked in CF7, but breaks in CF8.
When I try to check the cfdocument.currentpagenumber reserved variable,
I get the ERROR:
"Element CURRENTPAGENUMBER is undefined in CFDOCUMENT. "

The code is outside of any cfdocumentitem tag, but within the main cfdocuent
tag where format="pdf". This has been working until CF8...TIA...
# Posted By Roy Arnold | 1/30/08 7:13 AM
I just ran into a similar issue with CFDOCUMENTITEM in CF8 (with hot fix 2 installed). Within the CFDOCUMENTITEM tag, we were seeing problems where SESSION scoped variables and struct elements were supposedly not defined (although the errors could not be reproduced 100% of the time).

Once I set a variable in the VARIABLES scope just before the CFDOCUMENTITEM tag and referred to that, it worked fine.
# Posted By Chris Herdt | 2/19/08 11:48 AM
I can confirm this is still an issue with hotfix 3. We're getting:

coldfusion.document.spi.DocumentExportException:
java.lang.NullPointerException

prefacing the query items with the query name fixes the problem as Dave shows.
# Posted By Kris Jones | 3/27/08 10:54 AM
With CF 8.01 things are different, but, even worse...

Within cfdocumentitem you can NOT use variables with a query name prefix. (Although you should always prefix your variables.) Plus, if inside a CFC method, you can not use local variables inside cfdocumentitem. :-(

Chris
# Posted By Chris | 6/2/08 6:49 AM
I also experienced this error with unmatched html tags... so check that also...
# Posted By patrick | 7/7/08 11:48 AM
This drove me insane... I tried to use CFDOCUMENT within a CFC function and received errors telling me variables didn't exist when I was looking right at them. Turns out, thanks to Chris Herdt's comment, I had to throw every variable (which I wanted to use within CFDOCUMENT) into the VARIABLES scope. I was attempting Arguments.VarName, but I had to reassign it to Variables.VarName outside of CFDOCUMENT.

That's just stupid.

So, from what I've gathered, you cannot use Query, Arguments, or Session scopes within CFDOCUMENT (that is, in CF8 - this all worked in CF7). Although I haven't tested, I'd be willing to say that anything outside of the VARIABLES scope would thrown an error.

Enjoy.
# Posted By Rob O | 7/15/08 11:15 AM