网页上的HTML图像下载PDF文件

时间:2013-06-14 20:29:40

标签: c# html asp.net

是否有用户下载的示例方式,保存我在网页上的PDF文件?

目前我有:

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

只打开文件而不保存。寻找一种简单的方法来做到这一点。提前致谢。

2 个答案:

答案 0 :(得分:1)

如果您使用的是HTML5,则可以使用下载属性。以下是Google的示例。

另一个example

答案 1 :(得分:0)

是的,您可以使用content-disposition标头,它会强制Save As..对话框发送给用户。

因此,在您的图片上,您可以链接说出将为PDF提供服务的处理程序,或者在ImageButton中进行回发,然后提供该文件。

 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();
相关问题