0

Is there a sample way for the user to download, save the PDF file I have on my webpage?

Currently I have:

<tr><td><a href="../Presentation.pdf"><img src="../../images/speakernotes.png"/></a>

which just opens the file and does not save it. Looking for a easy way to do this. Thanks in advance.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
  • 1
    Depends on the browser and PDF reader installed. Some modern browsers have a built in PDF reader. So the only way to download from the link would be `Right Click` > `Save link as..` – Nick R Jun 14 '13 at 20:31
  • Avoid ../ paths wherever possible – Joel Coehoorn Jun 14 '13 at 20:32
  • Take a look [here](http://stackoverflow.com/questions/6794255/html-download-a-pdf-file-instead-of-opening-them-in-browser-when-clicked). — Yes, it is duplicated. – Guilherme Oderdenge Jun 14 '13 at 20:36

2 Answers2

1

If you are using HTML5 you can use the download attribute. Here is an example by Google.

Another example.

chockleyc
  • 581
  • 2
  • 5
0

Yes, you can use the content-disposition header which will force the Save As.. dialog to the user.

So on your image, you can link to say a handler which will serve the PDF, or perhaps do a postback in an ImageButton and then serve the file.

 String FileName = "FileName.pdf";
 String FilePath = Server.MapPath("~/yourPath");
 System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
 response.ClearContent();
 response.Clear();
 response.ContentType = "application/pdf";
 response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
 response.TransmitFile(FilePath);
 response.Flush();
 response.End();
Darren Wainwright
  • 30,247
  • 21
  • 76
  • 127