lmttag
lmttag

Reputation: 2499

Dynamically Created PDF Not Embedding/Rendering Inline in 64-bit IE9 Window

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!

Upvotes: 2

Views: 4642

Answers (5)

Vaishali Kulkarni
Vaishali Kulkarni

Reputation: 521

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!

Upvotes: 0

Rawdon Hume
Rawdon Hume

Reputation: 31

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)

Upvotes: 3

iPDFdev
iPDFdev

Reputation: 5834

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

Upvotes: 2

Lynn Crumbling
Lynn Crumbling

Reputation: 13357

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.

Upvotes: 1

competent_tech
competent_tech

Reputation: 44931

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.

Upvotes: 1

Related Questions