【问题标题】:Unable to save a PDF if opened in Chrome如果在 Chrome 中打开,则无法保存 PDF
【发布时间】:2012-09-15 02:43:47
【问题描述】:

我编写了一个 ASP.NET (C#) 应用程序来在线创建 PDF 并在浏览器中显示。

    string path = @pdf_path;
    WebClient client = new WebClient();
    byte[] buffer = client.DownloadData(path);      

    if (buffer != null)
    {
        Response.ContentType = "application/pdf";
        Response. AddHeader("content-length", buffer.Length.ToString());
        Response.BinaryWrite(buffer);
    }

如果我使用 Internet Explorer 和 Mozilla Firefox,我可以保存并打印它。但是如果我用 Chrome 打开它并单击保存按钮,则会保存 aspx 页面,而不是 PDF。

如何让 Chrome 显示 PDF 或显示并建议用户启用某些功能?

【问题讨论】:

  • 我猜你应该在 chrome 上安装 pdf 插件

标签: c# asp.net google-chrome pdf


【解决方案1】:

在 Chrome PDF 模式下,您只需将鼠标指针移至靠近右下角的位置,您就会得到一个带有保存按钮的小工具栏。

【讨论】:

    【解决方案2】:

    如果你想强制浏览器下载文件添加这个头

    Response.AppendHeader("Content-Disposition", "attachment;filename=" + "Sample.pdf");
    

    但是如果你启用了它的 pdf 查看器,你的代码可以在 chrome 中工作:

    最新版本的 Google Chrome(6 及更高版本)内置了 PDF 支持,但默认情况下未启用。

    在 chrome 中输入 about:plugins 并搜索 pdf viewer 并启用它

    How To Enable the Built-in PDF Viewer in Google Chrome

    【讨论】:

      猜你喜欢
      • 2018-05-21
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多