2

I am working on a C# ASP.NET web application. We have created a hyperlink which will open a PDF document. The PDF document needs to be opened inline in the browser. On Chrome on the desktop it works fine. On Chrome on android it downloads the PDF document. How can I fix it so that it will open the PDF inline on both devices?

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();
Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
Jax
  • 53
  • 2
  • 6
  • Possible duplicate of [How to display a PDF via Android web browser without "downloading" first](http://stackoverflow.com/questions/7437602/how-to-display-a-pdf-via-android-web-browser-without-downloading-first) – JimmyB Apr 14 '16 at 12:35
  • there is no solution, and I think my question is not the same. – Jax Apr 18 '16 at 10:07

1 Answers1

0

The fix was to use this 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(" ","")));
Jax
  • 53
  • 2
  • 6