动态创建的 PDF 未在 64 位 IE9 窗口中内联嵌入/渲染

发布于 2024-12-20 13:12:20 字数 1599 浏览 0 评论 0原文

我们正在使用 Reporting Services 生成 PDF 报告,并且需要将其呈现到浏览器窗口并嵌入到浏览器中。我们已经这样做了很长时间并且一直有效......直到 IE9。

在 IE6、IE7 和 IE8 中,我们从 Reporting Services 生成表示 PDF 报告的字节数组,并将其二进制写入到浏览器,一切正常。 PDF 显示嵌入在浏览器中。

在 IE9 中,我们尝试了同样的操作,PDF 没有嵌入到浏览器窗口中。浏览器窗口保持打开状态并且为空白,并且 PDF 在 Adob​​e Reader 中的单独窗口中打开。

以下是我们的代码片段:

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) 
{ 
    // ... 
} 

我们怎样才能在 IE9 浏览器窗口中呈现并嵌入 PDF?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

絕版丫頭 2024-12-27 13:12:20

希望这可能对其他人有帮助,我发现了一种使用 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);
          });
    }
 }

,然后只需向页面添加一个 div :

yourpage1 是调用和流式传输 pdf 并设置缓存标头的页面,

然后 yourpage2 是一个 aspx 页面,其中包含上面有一个 iram,我动态设置 src:
iframeid.Attributes.Add("src", "yourpage1.aspx?"pram1=" & Request.QueryString("PramVal1") )
请注意,ifram 需要在服务器标记上运行,您可能希望它加载 iram 高度 100%,您可以这样做
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>

如果用户是 IE 32 位,那么这个剂量是多少,然后打开一个新窗口,显示其中的 pdf(实际上在一个框架中,但你无法分辨),或者如果他们是 IE 64,则完全跳过使用窗口并加载将 pdf 直接流式传输到我们页面的页面。这迫使 adobe pdf 不是在浏览器窗口中打开,而是直接作为 pdf 打开,因此所有这些在 64 和 64 和 64 中都可以工作并且看起来不错。 32 IE

我确实发现流读取器引起了问题,但这效果很好,

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)

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)
秋日私语 2024-12-27 13:12:20

Internet Explorer 64 位只能运行 64 位插件。 Adobe PDF 插件是 32 位的,无法在 64 位 IE 中运行。

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

千寻… 2024-12-27 13:12:20

看看这个论坛帖子:
http://forums.adobe.com/message/3331557#3331557#3331557

此外,整个线程讨论了使不同版本的 IE 正常工作的不同修复。有多种原因可能导致此问题。

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

一位读者还指出,它必须以 PDF 结尾,看起来就像你正在做的那样。

请记住,如果您使用不同版本的 acrobat reader,此问题实际上可能与 Reader 中的更改有关,而不是 IE。


在您的评论中,您指出了 64 位问题。查看有关 IE8/64 位 vista 的 SO 答案:
无法显示来自 HTTPS 的 PDF IE 8(在 64 位 Vista 上)

看来您已经做了他在最终答案中所说的需要做的所有事情(即,将缓存控制设置为私有,并且没有 设置Pragma:无缓存。)

值得注意的是,各种响应都采用了手动添加标头的方式:通过以下方式手动添加标头:

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

而不是调用

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

Unsure,这是有区别的,但可能值得一试。

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.

往日情怀 2024-12-27 13:12:20

请务必注意,内联显示 PDF 实际上可以通过 Acrobat Reader 设置进行控制。

在菜单Edit>中首选项...,从左侧导航中选择Internet,并确保选中在浏览器中显示 PDF

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.

叹沉浮 2024-12-27 13:12:20

看来64位IE9有一个bug;如果用于要显示的 PDF 文件的输出流的文件扩展名是大写的,例如“myFile.PDF”,而不是小写的“myFile.pdf”,则输出流的 mimeType 不会被识别为 application/pdf。它默认为 mimeType 文本。这种页面根本不渲染,或者部分渲染或者以某种不可读的字体渲染。如果文件扩展名是大写的,请尝试使用小写的 .pdf 文件扩展名。
祝你好运!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文