Search code examples
coldfusioncoldfusion-8cfdocument

Cfdocument being served by server despite being in cfsavecontent


It seems that when I use the <cfsavecontent> tag, the output of that is being served by the server (without the variable being outputted), which, to me, kind of defeats the purpose of <cfsavecontent>.

If this is important: my application uses ColdSpring, ModelGlue and Transfer ORM.

Here's my example code in a function:

<cfsavecontent variable="testvar">
<cfinclude template="test.cfm" />
</cfsavecontent>
<cfreturn testvar>

And the template:

<cfdocument format="PDF" pagetype="A4" orientation="portrait" unit="cm">
<cfoutput>
<!--- PDF content here --->
</cfoutput>
</cfdocument>

The PDF content is being parsed by my browser (Google Chrome), while the view hasn't even been loaded in. How can I best prevent this from happening?

Just to clarify: I am not outputting the #testvar# variable yet in this code, though it seems it loads the template in the browser anyways.


Solution

  • As I also needed to make multiple PDF documents merge, I ended up doing the following. Many thanks to Adam Cameron for providing the solution to my initial issue.

    • In the template file, I use the <cfdocument> tag with the name attribute to save the PDF in a variable (thanks to Adam Cameron for this)
    • Then, I store all the PDF documents in an array in their binary format
    • In my view, I merge the PDF documents together by using <cfpdf>'s merge action, and using a cfloop, to loop over the array, inside it.
    • Finally, I display the content by using <cfcontent> and using the variable attribute with toBinary(myPdf)

    This got me to where I am.