PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Generated PDF not showing in IE but showing in Firefox
https://forum.pdfsharp.net/viewtopic.php?f=2&t=30
Page 1 of 1

Author:  brogge [ Wed Nov 29, 2006 10:45 am ]
Post subject:  Generated PDF not showing in IE but showing in Firefox

Hello PDFSharp experts,

I recently started experimenting with the PDFSharp library and so far everything went well.

I now create a PDF on the fly and am trying to serve this through my webserver (IIS 6.0) to the client. In Firefox this is working fine. For some reason I'm not seeing anything in Internet Explorer. IE just shows a blank page.

This is the code that I've created (which is almost exactly the same as the web example).

// Send PDF to browser
MemoryStream stream = new MemoryStream();
document.Save(stream, false);

// document.Save(@"c:\inetpub\winscout\content\test.pdf");
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
Response.End();

stream.Close();

When I save the file to disk it can be opened in a PDF-viewer. So the file itself looks OK.

Any suggestions on why IE refuses to show the file ?

Thanks in advance,

boris

Author:  Thomas Hoevel [ Wed Nov 29, 2006 10:59 am ]
Post subject: 

Does IE display other PDF files?
On my computer IE has a problem displaying PDF files - probably because I installed 2 versions of Adobe Acrobat.

IE displays PDF files if I manually launch Acrobat Reader 7 before clicking the link in IE.
I get a blank page if I click a link in IE w/o an open Acrobat Reader.

Author:  brogge [ Wed Nov 29, 2006 11:04 am ]
Post subject: 

Hi Thomas,

IE displays PDF files when I click for example a link in a web page. That is why I was guessing that I did something wrong with http-headers (but then again: Firefox seems to work fine).

Whether Adobe Acrobat Reader is started or not doesn't seem to make a difference. As far as I know I have only one version of acrobat installed. I'm running IE 7.



boris

Author:  natethornton [ Thu Dec 21, 2006 5:20 pm ]
Post subject:  You need the following to work in both IE and Firefox

Here is the code you need to make it work in both IE and Firefox, and open inside the browser window:


MemoryStream stream = new MemoryStream();
document.Save(stream, false);

Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Accept-Header", stream.Length);
Response.AddHeader("Content-Length", stream.Length);
Response.OutputStream.Write(stream.GetBuffer(), 0, stream.Length);
Response.Flush();
Response.End();

stream.Close();

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/