简体   繁体   English

如何在chrome android上强行打开pdf文档内联?

[英]How to force open pdf document inline on chrome android?

I am working on a C# ASP.NET web application. 我正在开发一个C#ASP.NET Web应用程序。 We have created a hyperlink which will open a PDF document. 我们创建了一个打开PDF文档的超链接。 The PDF document needs to be opened inline in the browser. 需要在浏览器中内联打开PDF文档。 On Chrome on the desktop it works fine. 在桌面上的Chrome上运行正常。 On Chrome on android it downloads the PDF document. 在Android上的Chrome上,它会下载PDF文档。 How can I fix it so that it will open the PDF inline on both devices? 如何修复它以便在两个设备上打开PDF内联?

This is my code: 这是我的代码:

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();

The fix was to use this contenttype: 修复是使用此contenttype:

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

It was also needed to remove spaces in the filename: 还需要删除文件名中的空格:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM