views:

124

answers:

4

I'm using link tag to open a pdf file. when clicking that link, the pdf file is opened directly. Is it possible to donwload and save the pdf file to my system through html?

+2  A: 

You cannot force this behaviour using plain html only.

The server needs to send a Content-Disposition: attachment;filename=x.pdf header to achieve this.

ChristopheD
+2  A: 

You should change the headers sent to client by server and add something like.

Content-Disposition: attachment; filename="downloaded.pdf"

It can be done with proxy php script or by configuring your webserver.

stroncium
Good job mentioning the `filename`. It is so annoying when an HTTP request to a URL like e.g. `http://example.com/download.php?stuff.pdf` pops up a "Save As" dialog wanting to save the downloaded PDF file as `download.php`. Please *do* send a `filename=stuff.pdf` in those cases.
ndim
A: 

i dont think you cand do it from HTML ... this is done via headers, you can modify them either in the backend language or via apache headers

solomongaby
+2  A: 

Short answer is no: PDF handling depends entirely on client side software, from web browser to PDF reader. Your server can provide hints that can be used by the browser (or not) but you won't accomplish it with plain HTML.

Whatever, you can probably configure your web server to send appropriate HTTP headers. If you are using Apache, you can use an .htaccess file:

<FilesMatch "\.(?i:pdf)$">
  ForceType application/pdf
  Header set Content-Disposition attachment
</FilesMatch>

If you replace application/pdf with application/octet-stream you might even bypass the PDF plug-in if installed (not guaranteed though).

Other web servers will require different config.

Álvaro G. Vicario
I'm using aspnet. Shall I add in web.config ?
Nila