I want to force the browser to download a pdf
file.
I am using the following code :
<a href="../doc/quot.pdf" target=_blank>Click here to Download quotation</a>
It makes the browser open the pdf in a new window, but I want it to download to the hard drive when a user clicks it.
I found that Content-disposition
is used for this, but how do I use it in my case?
With recent browsers you can use the HTML5 download attribute as well:
It is supported by most of the recent browsers except MSIE11. You can use a polyfill, something like this (note that this is for data uri only, but is is a good start):
On the HTTP Response where you are returning the PDF file, ensure the content disposition header looks like:
See content-disposition on the wikipedia MIME page.