Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

To achieve what you're trying to do, should you not simply be using the name attribute of <cfdocument> to put the PDF data into a variable, instead of trying to <cfsavecontent> it?

Disclosure: I've never used <cfdocument> for anything other than proof-of-concept code and testing, but that's what I'm inferring from the docs.

cfinclude will process the test.cfm page, and the way you configured cfdocument will cause "opening" of pdf document in your browser. You can prevent openning of this file by saving file on the disc:

<cfdocument format="PDF" pagetype="A4" orientation="portrait" unit="cm" filename ="test.pdf" overwrite ="yes">

But this will not prevent execution of cfinclude in the cfcontent tag, it will just prevent opening in the browser.

You can observe cfinclude as request to the server, it will always be executed.

The solution would be to invoke request on test.cfm file which contains cfdocument in the moment that you actually want to generate pdf.

Example: Use javascript on client to invoke report service which will generate and pop out the screen with pdf report.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top