function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Veenesh VikramVeenesh Vikram 

Force Download a Static PDF document from a button click

How can we "Force Download" a static PDF File stored as a Static Resource/Document in a VF Page? By Force Download, I mean that the File shoulld be downloaded straight away to the user's local machine and not open in a new Tab as a PDF. 
Siddharth83JainSiddharth83Jain
Hi Veenesh,

Try this below may be you can change the styling later
<a href="/servlet/servlet.FileDownload?file={!attachmentInstance.Id}" target="_blank" styleClass="btn">Download</a>

It will try to open your document in a new tab. If it is image/pdf that can be opened in browser, it will open in new tab, otherwise it will download the file. Basically it more of browsers behavior too.

Please mark this as best answer if it helps

Thanks
Siddharth 
OSI Consulting
Veenesh VikramVeenesh Vikram
Hi Siddharth,

I know that opening a document in new tab is the standard behavior.What I am looking for is a solution to Force the download, like we can do in VF page by setting the "content-desposition" on page header. Here the issue i am facing is that its not a VF page but a static document, so i cannot set the content desposition.

Veenesh
Siddharth83JainSiddharth83Jain
Try this out

window.location.assign(url);

If it helps then mark as best answer.

Thanks
Siddharth 
OSI Consulting