Vicki
Vicki

Reputation: 1456

ColdFusion PDF "Open with" or "save file" prompt

How can I create a pop up that allows the user to "open with" or to save file as when dealing with coldfusion pdf's?

enter image description here

I am trying to figure out how to create it when this form is not actually mine and I am just using and prefilling a form that already exists.

<cfpdfform source="82040.pdf" action="populate">
   <cfpdfformparam name="cust ##" value=""> <!---Section1 Customer Number--->
</cfpdfform>

I was able to create this pop up by doing something like this:

<cfsetting enablecfoutputonly="true">
<cfcontent type="application/pdf">
<cfheader name="Content-Disposition" value="attachment;filename=test.pdf">
<cfdocument format="PDF" localurl="yes" 
    marginTop=".25" marginLeft=".25" marginRight=".25" marginBottom=".25" 
    pageType="custom" pageWidth="8.5" pageHeight="10.2">
<cfoutput><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>PDF Export Example</title>
</head>
<body>
</body>
</html>
</cfoutput>
</cfdocument>

But am not sure how I can combine these two. Any help is greatly appreciated!

Per Request What I have tried:

<cfset tempFilePath = "c:/path/to/someUniqueFileName.pdf">
<cfpdfform source="82040.pdf" action="populate" destination="#tempFilePath#">
    <cfpdfformparam name="org" value="Yes"> <!---Above Section1 Original --->  <!---On--->
</cfpdfform>
<cfheader name="Content-Disposition" value="attachment;filename=Testme.pdf">
<cfcontent type="application/pdf" file="#tempFilePath#" deleteFile="false">

Upvotes: 2

Views: 774

Answers (1)

Leigh
Leigh

Reputation: 28873

By default, cfpdfform renders the result in the browser ie "inline". To return it as an attachment instead, save the content to a file or a variable. Then use cfheader/cfcontent to return it as an attachment.

File:

Use the "destination" attribute to save it to a file. To avoid conflicts with other threads be sure use unique file names. To automatically remove the temporary file when finished, set deleteFile="true"

<cfset tempFilePath = "c:/path/to/someUniqueFileName.pdf">
<cfpdfform source="82040.pdf" action="populate" destination="#tempFilePath#">
  ...
<cfheader name="Content-Disposition" value="attachment;filename=test.pdf">
<cfcontent type="application/pdf" file="#tempFilePath#" deleteFile="false">

Variable:

Use the "name" attribute to save the content to a variable. Though "name" is not listed in the documentation, this bug report suggests it is just a documentation error.

<cfpdfform source="82040.pdf" action="populate" name="pdfContent">
... etcetera ...
<cfheader name="Content-Disposition" value="attachment;filename=test.pdf">
<cfcontent type="application/pdf" variable="#toBinary(pdfContent)#">

Upvotes: 1

Related Questions