0

我编写了一个 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 或显示并建议用户启用某些功能?

4

2 回答 2

0

if you want to force the browser to download the file add this header

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

but your codes works in chrome if you enable its pdf viewer :

The recent releases of Google Chrome (6 and up) have PDF support built-in, but it's not enabled by default.

type about:plugins in chrome and search for pdf viewer and enable it

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

于 2012-09-23T17:52:29.117 回答
0

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

于 2012-09-23T11:02:57.477 回答