【问题标题】:HTML image on webpage to download PDF File [duplicate]网页上的 HTML 图像以下载 PDF 文件 [重复]
【发布时间】:2013-06-15 04:56:40
【问题描述】:

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

目前我有:

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

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

【问题讨论】:

  • 取决于安装的浏览器和 PDF 阅读器。一些现代浏览器具有内置的 PDF 阅读器。所以从链接下载的唯一方法是Right Click > Save link as..
  • 尽可能避免使用 ../ 路径
  • 看看here。 — 是的,它是重复的。

标签: c# html asp.net


【解决方案1】:

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

另一个example

【讨论】:

    【解决方案2】:

    是的,您可以使用 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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多