0

I am trying to open a PDF document to display within IE6. I am using the following snippet:

response.ContentType = healthMedia.MediaKey.MimeType;
response.ClearHeaders();     

response.AddHeader("Content-Disposition", "inline; filename=" + mediaKeyId);

int contentLength = healthMedia.Content.Length;
response.AppendHeader("content-length", Convert.ToString(contentLength));
response.OutputStream.Write(healthMedia.Content, 0, contentLength);

healthMedia.MediaKey.MimeType; is equal to 'application/pdf'

This brings up the Save dialog. If I comment out Response.ClearHeaders(); I get a new window to popup but it's contents is a bunch of jibberish (random encoding text).

How can I get IE6 to open the PDF correctly?

-Nick

Nick
  • 19,198
  • 51
  • 185
  • 312
  • Looks like you're doing it right. Have you tried opening PDFs from other websites in IE6? It may be that the Adobe Reader plugin for your IE6 browser is not configured correctly. – Chris Van Opstal Jan 12 '10 at 14:13
  • Haha! I guess when I saw the browser trying to download a PDF this should have occurred to me. Thanks – Nick Jan 12 '10 at 14:18
  • ...for values X of “correctly” ;-) The Adobe Reader plugin is responsible for the largest proportion of web exploits of any software at the moment. To allow a PDF reader to run as a net-facing plugin is foolhardy. – bobince Jan 12 '10 at 14:37

3 Answers3

0

Have you tried Response.End() and also Response.Buffer = true? You may also need to set a caching policy.

Chris S
  • 64,770
  • 52
  • 221
  • 239
  • This is from memory, I prefer providing PDFs as attachments to avoid freezing their browser with the terrible Acrobat Reader plugin. – Chris S Jan 12 '10 at 14:17
  • Thanks Chris.. after clearing the header the browser was attempting to download the pdf. The plugin was missing. I am currently adding this header response.AppendHeader("content-length", Convert.ToString(contentLength)); Is that what you are suggesting? – Nick Jan 12 '10 at 14:35
  • Also ending the response and making it buffered is needed in IE6 (I think) – Chris S Jan 12 '10 at 15:04
0

In case it helps, here's a method I've used before to render in-browser PDFs...

Community
  • 1
  • 1
lance
  • 16,092
  • 19
  • 77
  • 136
0

Use response.BinaryWrite() instead of response.OutputStream.Write()

Josh Stodola
  • 81,538
  • 47
  • 180
  • 227