开发者

PDF coming as text on browser

I am trying to display a PDF from database (byte[]) to user.

I am using code below to render PDF. It is giving me PDF as binary text as shown below. Instead of open in PDF application it is rendering PDF as text.

Response.Buffer = true;
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        //Response.AddHeader("Content-Length", fileToDownload.Length.ToString());
   开发者_运维知识库     //Response.AddHeader("Content-Disposition", "inline; name=RemoteUserGuide.pdf");
        Response.AppendHeader("content-length", fileToDownload.Length.ToString());
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(fileToDownload);
        Response.Flush();
        ////Response.Close();
        Response.End();

UPDATE: Just noticed, this application page is rendering PDF correctly in CHROME, but still displaying text in IE. (don't have FF3 on server to test). Probably its some browser issue?

Any Ideas?

PDF coming as text on browser


Corrupted adobe install does this. reinstall Adobe Reader on the target (client) machine.

Sometimes the Adobe Installer crashes and does this.


If you are sure, that your browser can view pdf, then you should use @PAGE ContentType="application/pdf" directive instead of Response.ContentType = "application/pdf";

Also you should use the Response.AddHeader("content-disposition", "filename=\"document.pdf\"" ); for setting filename


Make sure your MIME type for the .pdf extension in IIS (Internet Information Services) is set to "application/pdf".


As the others said, try setting the MIME type / header to application/pdf, if this doesn't work the last thing is closing your browser and reopening the same page, I had this problem before with FPDF (a PDF generation library in PHP), it looks like the browser cache the MIME of the page (php) and keep it forever, by closing the browser and reopening it, it will work #1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜