Open a PDF in a new browser window with ColdFusion cfpdfform

9.3k views Asked by At

I'm using ColdFusion 8 to and the object to create an xml document and then write the data to fields in an existing PDF file on our intranet. The problem is that I need the PDF to open in a new browser window, not the same browser window, which is what is happening now.

Is there any additional info I can pass along with the 'destination=' tag to force the PDF form to open in a new browser window?

Thanks in advance for all replies

2

There are 2 answers

0
isurfbecause On

I was looking for the answer and coworker steered me towards this easy solution. This will open a pdf in a new web browser window.

<a href="showPdf.cfm?filePath=#filePath#" target="_blank">test.pdf</a>

index.cfm (calling page)

<cfheader name="Content-disposition" value="inline;filename=test.pdf">

<CFCONTENT TYPE="application/pdf" FILE="#url.filePath#" DELETEFILE="No">

showPdf.cfm

2
Timothy Allyn Drake On

Providing code examples in the future would be greatly appreciated and should expedite resolution. However, if I am understanding you correctly, and depending on your preference, then one of the following solutions should suffice.

ColdFusion (Server-side)

If you are NOT writing the newly populated PDF to disk:

<cfpdf name="variableName" />
<cfheader name="Content-Disposition" value="attachment; filename=filename.pdf" />
<cfcontent type="application/pdf" variable="#toBinary(variableName)#" />

OR

If you ARE writing the newly populated PDF to disk:

<cfpdf action="write" destination="c:\full\path\to\filename.pdf" />
<cfheader name="Content-Disposition" value="attachment; filename=filename.pdf" />
<cfcontent type="application/pdf" file="c:\full\path\to\filename.pdf" />

OR

HTML (Client-side)

<a href="/relative/url/to/pdf/populate/template.cfm" target="_blank">Anchor Text</a>

OR

JavaScript (Client-side)

window.open("/relative/url/to/pdf/populate/template.cfm", "windowName");