2

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

Alan
  • 21
  • 1
  • 2
  • Alan, you may have a good reason for doing this, but just to note that in general opening items in a new window can cause confusion, especially to inexperienced users. This is because the first window history doesn't transfer and they struggle to understand why the Back button no longer works. – CfSimplicity Sep 13 '11 at 08:05

2 Answers2

4

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");
  • Timothy, AFAIK, this is not something you can do server-side. Your first 2 suggestions with CFHEADER will normally just cause the PDF to be downloaded to disk rather than opened in the browser. Javascript is the way to go to have the PDF open in a new window. – CfSimplicity Sep 13 '11 at 07:59
  • I absolutely agree, however, the lack of provided details resulted in my providing many options in hopes to suffice one of the answers I felt he may have been seeking. Thank you for your feedback. – Timothy Allyn Drake Sep 13 '11 at 08:03
0

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

isurfbecause
  • 990
  • 4
  • 16
  • 30