【问题标题】:How to force open pdf document inline on chrome android?如何在 chrome android 上强制打开 pdf 文档内联?
【发布时间】:2016-08-05 23:56:32
【问题描述】:

我正在开发一个 C# ASP.NET Web 应用程序。我们创建了一个超链接,它将打开一个 PDF 文档。 PDF 文档需要在浏览器中内联打开。在桌面上的 Chrome 上它工作正常。在 Android 上的 Chrome 上,它会下载 PDF 文档。如何修复它,以便它可以在两个设备上打开 PDF 内联?

这是我的代码:

var document = sessionManager.DocumentServiceClient.GetDocument(documentId, documentStorageType);

this.Response.Clear();
this.Response.ContentType = "application/pdf";
this.Response.AddHeader("Content-Disposition", string.Format("inline; filename = \"{0}.pdf\"", this.DocumentTitle));
this.Response.OutputStream.Write(document.FileData, 0, document.FileData.Length);
this.Response.End();

【问题讨论】:

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


【解决方案1】:

解决方法是使用此内容类型:

this.Response.ContentType = "application/octet-stream";

还需要删除文件名中的空格:

this.Response.AddHeader("Content-Disposition", string.Format("inline; filename = \"{0}.pdf\"", this.DocumentTitle.Replace(" ","")));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-12
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 2019-08-07
    • 1970-01-01
    • 2012-03-30
    相关资源
    最近更新 更多