An .aspx page has a .pdf file in it, like this: <embed src="http://.../ShowPdf.aspx?id=1" type="application/pdf">
. Chrome just shows a "Loading" image and hangs without displaying the pdf (chrome pdf viewer and adobe plugin both don't work). Other browsers open the pdf. Any ideas?

- 1,219
- 1
- 10
- 18
3 Answers
I had this problem too and I finally solved it after several researches.
What I found is that the HTTP
response header should have the following entity-header:
content-length: file size
Without specify this header, the web server will put the default:
content-length: chunked
I don't know why Google Chrome has this issue, because as you said, in other browsers like IE or Firefox, they render/open correctly the PDF file.
Following is my code that I used to solve this problem. It worked in my case and now Google Chrome is displaying the PDF file of my web application!
System.IO.FileInfo fileInfo;
fileInfo = My.Computer.FileSystem.GetFileInfo(fullPathToFile);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
I hope that I had helped you.
Here are some references that I found useful:
PDF Handler Problem with Chrome & Firefox
What's the “Content-Length” field in HTTP header?
Thank you very much, I had the same problem, and it was the solution. I was using a report viewer, but i needed to show it in pdf automatically, and it was working correctly, but when i used Chrome, it had the same issue, when i want to save the file, it was saved with extension .ASPX and not with .pdf.
I share my code with the solution:
string deviceInfo = "";
string[] streams = null;
string mimeType = null;
string encoding = null;
string fileNameExtension = null;
Warning[] war = null;
Byte[] bytes = this.ReportViewer.LocalReport.Render("PDF", deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out war);
System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
Response.Clear();
Response.ContentType = "Application/pdf";
Response.AddHeader("Content-Length", bytes.Length.ToString());
Response.AddHeader("Content-disposition", "inline; filename= NombreReporte");
Response.BinaryWrite(ms.ToArray());
Response.Flush();
Response.End();

- 21
- 1
If you also have the problem showing a PDF in Firefox, I found this:
"You need to specify the content type so the browser knows what file it is downloading / showing inline....like so:"
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "inline;filename=YourFileName.pdf")
It´s worked for me, I hope for you too and help you.

- 21
- 1