Chrome not displaying PDF from asp.net page

.net, google-chrome, pdf

Solution

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?

Problem

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?

Original source

Related problems