ColdFusion: trying to create dynamic downloadable PDF, but not create a file?

1.2k views Asked by At

I haven't been able to find an answer to this ColdFusion/PDF question so here goes:

I already have a back-end that creates dynamic PDFs using CFDOCUMENT. The user has to submit payment first via authorize.net, then once the payment is processed, they click a link to download a dynamic PDF we create.

The PDF is saved in a file on our server. The link the user clicks to download it calls CFHEADER and CFCONTENT which points to the PDF location on the server and it downloads for them.

However, I don't want to store the PDFs on the server anymore if I don't have to. I'd like them to be able to click the link to download, then have the PDF be generated dynamically, be available for download, but not saved on the server.

Is this possible? Or do you have to create a file for them first if they want to download a dynamically created PDF?

2

There are 2 answers

3
Dan Bracuk On BEST ANSWER

Here is how I do it on a test page I have in version 9.

<cfdocument format="pdf">
Hello.  This is a very simple pdf file.
</cfdocument>

It is called by this anchor tag.

<a href="pdf_output.cfm" target="_blank">
Click here to open new tab/window with pdf content that is generated at runtime.
</a>
1
BaldProgrammer On

Your link can send them to a page with something like this, where #thePDF# contains a binary object created from <cfdocument name="thePDF" ...>:

<cfheader name="content-disposition" value="attachment; filename=mypdf.pdf"/>
<cfcontent type="application/pdf" variable="#thePDF#" />