2

We're using Reporting Services to generate a PDF report and we need it to be rendered out to the browser window AND embedded in the browser. We've been doing this a long time and it has always worked ... until IE9.

In IE6, IE7, and IE8, we generate the byte array from Reporting Services that represents the PDF report and binary write it out to the browser, and everything works great. The PDF displays embedded in the browser.

In IE9, we try the same exact thing and the PDF is NOT embedded in the browser window. The browser window stays open and is blank/empty, and the PDF is opened in Adobe Reader in a separate window.

Here's a snippet of our code:

try 
{ 
    // Set all the Reporting Services variables and parameters and render the report 
    // ... 
    byte[] result = rs.Render(format, devInfo, out extension, out mimeType, out encoding, out warnings, out streamIDs); 

    // Force the render out of the report to the browser 
    Response.Clear(); 
    Response.ClearContent(); 
    Response.ClearHeaders(); 
    Response.AppendHeader("content-length", result.Length.ToString()); 
    Response.AppendHeader("Pragma", "cache"); 
    Response.AppendHeader("Expires", "3600"); 
    Response.Buffer = true; 
    Response.Cache.SetCacheability(HttpCacheability.Private); 
    Response.CacheControl = "private"; 
    Response.Charset = System.Text.UTF8Encoding.UTF8.WebName; 
    Response.ContentEncoding = System.Text.UTF8Encoding.UTF8; 

    switch (outputformat) 
    { 
        case "PDF": 
            Response.AppendHeader("content-disposition", "inline; filename=report.pdf"); 
            Response.ContentType = "application/pdf"; 
            break; 
        default: 
            break; 
    } 

    Response.BinaryWrite(result); 
    Response.Flush(); 
    Response.Close(); 
    Response.End(); 
} 
catch (System.Exception ex) 
{ 
    // ... 
} 

What can we do to get the PDF rendered and embedded in the IE9 broswer window?

Thanks!

Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
lmttag
  • 2,499
  • 4
  • 26
  • 30
  • Can you include acrobat reader version information? (both on the IE 6/7/8 boxen and the one used in combination with IE9) – Lynn Crumbling Dec 09 '11 at 15:35
  • 1
    Thanks for the info, Lynn. It was helpful. I tried Adobe Reader versions 9.4.6 and 10.1.1 (on two separate computers - both Windows Server 2008 R2, with IE9), and both versions of Reader had the same problem. The issue appears to stem from using the 64-bit version of IE9. When using the 64-bit version of IE9, the PDFs open in the Adobe Reader app, not in the browser window. If we use the 32-bit version of IE9, the PDF opens in the browser window as always has for us in previous versions of IE and Adobe Reader. So, something to note, use the 32-bit IE in this situation. – lmttag Dec 09 '11 at 18:14
  • Added to my already existing answer. Are you sending via http or https? – Lynn Crumbling Dec 09 '11 at 19:45

5 Answers5

3

hope this might help others, I found a hack/work around of sorts using jquery

function MyFunction(someprams) {
    if (navigator.userAgent.indexOf("x64") == -1) {
        window.open("yourpage2.aspx?PramName=PramVal, 'winowname', 'window opions here')
    } else {
        $.get("yourpage1.aspx", { PramName1: PramVal1, PramName1: PramVal1 },
          function(data) {
              $('#divid').html(data);
          });
    }
 }

so then just add a div to the page :

yourpage1 is the page what calls and streams the pdf and set the cache headers

then yourpage2 is a aspx page that has an ifram on it that i set the src dynamicly : iframeid.Attributes.Add("src", "yourpage1.aspx?"pram1=" & Request.QueryString("PramVal1") ) note the ifram need a run at server tag, aslo ur probally want it to load the ifram height 100% which u can do css:

html { height: 100%;}
body { height: 100%;}

html:

<iframe id="iframeid"  runat="server" scrolling="no" marginwidth="0" marginheight="0"
        frameborder="0" vspace="0" hspace="0" style="overflow: visible; width: 100%;
        height: 100%;"></iframe>

what this dose is if user is IE 32 bit then there get a new window open showing the pdf in it (actually in an frame but u cant tell) or if they are IE 64 then skip using window at all and load the page that streams the pdf directly into our page. This forces adobe pdf to open not in a browser window but directly as a pdf so all in all this works and looks ok in both 64 & 32 IE

i did find stream readers caused issues but this works nicely ,

Dim oWebClient As System.Net.WebClient = Nothing
Dim data() As Byte
try
 oWebClient = New System.Net.WebClient
 data = oWebClient.DownloadData(pdfurl)
//add Response.AddHeader stuff here e.g.
 Response.AddHeader("Content-Length", data.Length.ToString)
 Response.BinaryWrite(data)
2

Internet Explorer 64bit can run only 64bit plugins. The Adobe PDF plugin is 32bit and it cannot run in 64bit IE.

iPDFdev
  • 5,229
  • 2
  • 17
  • 18
1

Take a look at this forum post: http://forums.adobe.com/message/3331557#3331557#3331557

Also, this whole thread talks about different fixes to make different versions of IE work. There are multiple things that can cause this issue.

http://forums.adobe.com/thread/758489

One reader also noted that it MUST end in PDF, which it looks like you are doing.

Keep in mind, if you were using different versions of acrobat reader, this issue could actually be related to changes in Reader, and not IE.


In your comment, you noted a 64bit issue. Check out this SO answer re IE8/64bit vista:
Can't display PDF from HTTPS in IE 8 (on 64-bit Vista)

It appears that you're already doing everything that he said he needed to do, in his final answer (namely, setting Cache control to private, and not setting Pragma: no-cache.)

It's interesting to note, that the various responses have gone the way of manually adding the header via:

response.setHeader("Cache-Control","private");

Instead of calling

Response.Cache.SetCacheability(HttpCacheability.Private);  
Response.CacheControl = "private";

Unsure there's a difference, but it might be worth a shot.

Community
  • 1
  • 1
Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
  • It's useful for comment.. here's adobe's kb article where they really make it sound like this isn't supported. Unsure if this kb's up-to-date: http://kb2.adobe.com/cps/328/328233.html – Lynn Crumbling Dec 09 '11 at 19:38
1

It is important to note that displaying PDF inline can actually be controlled through Acrobat Reader settings.

In the menu Edit > Preferences..., select Internet from the left-hand navigation and ensure that Display PDF in browser is checked.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
0

It appears that there is a bug in 64 bit IE9; if the file extension being used for the outputStream of the PDF file to be displayed is in UPPERCASE e.g. 'myFile.PDF' instead of lowercase like 'myFile.pdf', the mimeType of the outputStream is not being recognized as application/pdf. It defaults to mimeType text instead. This kind of page does not render at all, or renders partially or renders in some unreadable font. Try using the lowercase .pdf file extension in case it is in uppercase. Good Luck!