Make PDF display inline instead of separate Acrobat Reader window

后端 未结 8 1835
别跟我提以往
别跟我提以往 2020-12-16 21:48

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

相关标签:
8条回答
  • 2020-12-16 21:59

    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.

    0 讨论(0)
  • 2020-12-16 21:59

    Here is an article on using the embed tag to do it:http://blogs.adobe.com/pdfdevjunkie/2007/08/using_the_html_embed_tag_to_di.html

    0 讨论(0)
  • 2020-12-16 21:59

    If you have the budget, my company sells a set of products that includes an AJAX based image viewer that will let you view the PDF pages in line without Acrobat at all. In its simplest form, it is just a viewer, but you can layer in interactivity as you need.

    0 讨论(0)
  • 2020-12-16 22:11

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

    context.Response.AddHeader("content-disposition", "inline; filename=Something.pdf")
    
    0 讨论(0)
  • 2020-12-16 22:15

    I think this header will do what you want

    Content-type: application/pdf
    

    Since you say that is not working, then I suspect it is a configuration setting on the client side.

    Check your installed version of Adobe Acrobat. There is a setting in preferences for "Internet" and a checkbox that says "Display PDF in Browser".

    --
    bmb

    0 讨论(0)
  • 2020-12-16 22:16

    OK, turns out it was a stupid question, but I'm glad I asked it because I had never heard of Fiddler (which led me to the answer, which is why I'm accepting tspauld's answer). The PDF is generated by a web service that serves the file to a couple of different front-end sites. I was setting the content disposition to inline in the service, but that didn't matter, because the browser never got that header; it got the header from the front-end site (which was attachment). I changed it in the front-end site and that fixed it.

    So the answer is that you have to have Content-Type=application/pdf and Content-Disposition=inline; filename=Something.pdf, as others have said.

    0 讨论(0)
提交回复
热议问题