• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfdocument: open download prompt to ask user where to save pdf

New Here ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

I'm using cfdocument to create a pdf. Displaying the pdf in the browser works fine, but I would like to just open a download prompt when the user opens that url.

<cfdocument format="PDF" localUrl="yes" margintop="0.25" orientation="landscape">

What I tried: I followed this and added a filename: https://community.adobe.com/t5/coldfusion-discussions/how-to-use-cfdocument-create-a-pdf-file-and-sa...

But it just saves that file in a lucee temp folder.

 

I also tried using a header like this:

<cfdocument format="PDF" localUrl="yes" margintop="0.25" orientation="landscape">
  ...
  Your PDF content goes here...
</cfdocument>

<cfheader name="Content-Disposition" value="attachment; filename=your-file-name.pdf">
<cfcontent type="application/pdf" file="#expandPath('your-file-path.pdf')#">

But it also doesn't open a download prompt.

 

What I want is that it opens a prompt and asks the user, where he wants to save that file.

Views

189

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 06, 2022 Dec 06, 2022

I think you're almost there. Try something like

 

<cfdocument format="PDF" localUrl="yes" margintop="0.25" orientation="landscape" filename="#expandPath('your-file-path.pdf')#">
  Your PDF content goes here...
</cfdocument>

<cfheader name="Content-Disposition" value="attachment; filename=your-file-name.pdf">
<cfcontent type="application/pdf" file="#expandPath('your-file-path.pdf')#">

 

 

Votes

Translate

Translate
Community Expert ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

I think you're almost there. Try something like

 

<cfdocument format="PDF" localUrl="yes" margintop="0.25" orientation="landscape" filename="#expandPath('your-file-path.pdf')#">
  Your PDF content goes here...
</cfdocument>

<cfheader name="Content-Disposition" value="attachment; filename=your-file-name.pdf">
<cfcontent type="application/pdf" file="#expandPath('your-file-path.pdf')#">

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2022 Dec 20, 2022

Copy link to clipboard

Copied

LATEST

Sorry for the late reply. 

Yes it solved the issue, but I need to add that also a browser setting might overwrite the save/show decision, based on the pdf settings (at least in Chrome). 

Thanks for your help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

Did that solve the problem?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation