Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make PDF display inline instead of separate Acrobat Reader window

I've got an ASP.NET ashx class that retrieves data from a database, creates a PDF file using iTextSharp, and streams the PDF to the browser. The browser (IE and Firefox at least) is launching Acrobat Reader as a separate window to open the file. I'd like for it to display inline within the browser.

Is that something I can completely control from the server side? I'm already setting the Content-Type header to application/pdf, and I've tried setting Content-Disposition and Content-Length. Nothing so far has worked.

Is there another header I'm missing? Is there something in the PDF itself that tells the browser how to display it? Any other ideas?

like image 348
John M Gant Avatar asked May 13 '09 19:05

John M Gant


2 Answers

Setting the content-disposition and content-type headers should do it, but you might also need to call Response.ClearHeaders() to clear other headers that have been set.

Also, try using Fiddler to see the actual headers and content from the response and compare them to those from a site that works like you want.

like image 121
tspauld Avatar answered Oct 11 '22 19:10

tspauld


If you are using an ashx (web handler) try this:-

context.Response.AddHeader("content-disposition", "inline; filename=Something.pdf")
like image 24
Christopher Edwards Avatar answered Oct 11 '22 17:10

Christopher Edwards