代码之家  ›  专栏  ›  技术社区  ›  Andrus

如何在ASP.NET中通过控制器在浏览器中打开PDF文件

  •  0
  • Andrus  · 技术社区  · 7 年前

    ASP.NET/Mono MVC4控制器将pdf文件发送到浏览器:

    public ActionResult Pdf() {
    Response.AppendHeader("Content-Disposition", "inline; filename=myfile.pdf");
    return File(<pdf content>, "application/pdf", "myfile.pdf");
    }
    

    对于多页文件,不显示文件。Chrome抛出错误

    ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION

    相反。

    If行

    Response.AppendHeader("Content-Disposition", "inline; filename=myfile.pdf");
    

    Duplicate headers and Calling the file in the wrong path

    Chrome提供下载PDF文件的功能。它不会自动在新选项卡中显示PDF。 如何强制Chrome在新选项卡中自动显示多页PDF内容?

    ASP.NET MVC4应用程序在Mono和Windows中运行。wkhtmltoppdf用于从Razor视图创建PDF文件。

    0 回复  |  直到 7 年前