我们正在使用Reporting Services生成PDF报告,我们需要将其呈现到浏览器窗口并嵌入浏览器中。我们已经做了很长时间了,它一直有效......直到IE9。
在IE6,IE7和IE8中,我们从Reporting Services生成表示PDF报告的字节数组,并将二进制文件写入浏览器,一切运行良好。 PDF显示嵌入在浏览器中。
在IE9中,我们尝试完全相同的事情,并且PDF未嵌入浏览器窗口。浏览器窗口保持打开状态,为空白/空,PDF在单独的窗口中在Adobe 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?
谢谢!
答案 0 :(得分:3)
希望这可能对其他人有所帮助,我发现使用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页面,上面有一个ifram,我动态地设置了src: iframeid.Attributes.Add(“src”,“yourpage1.aspx?”pram1 =“& Request.QueryString(”PramVal1“)) 请注意ifram需要在服务器标签上运行,因为我们想要它加载ifram高度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中看起来都很好。 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)
答案 1 :(得分:2)
Internet Explorer 64bit只能运行64位插件。 Adobe PDF插件是32位,无法在64位IE中运行。
答案 2 :(得分:1)
看一下这个论坛帖子: http://forums.adobe.com/message/3331557#3331557#3331557
此外,这整个主题讨论了不同的修复程序,以使不同版本的IE工作。有很多事情可能导致这个问题。
http://forums.adobe.com/thread/758489
一位读者也注意到它必须以PDF结尾,看起来你正在做。
请记住,如果您使用不同版本的acrobat阅读器,这个问题实际上可能与Reader中的更改有关,而不是IE。
在您的评论中,您注意到64位问题。看看这个SO答案是IE8 / 64bit vista:
Can't display PDF from HTTPS in IE 8 (on 64-bit Vista)
看起来你已经做了他说他需要做的所有事情,在他的最终答案中(即,将Cache控件设置为private,而 not 设置Pragma:no-cache。)
值得注意的是,各种响应已经通过以下方式手动添加标题:
response.setHeader("Cache-Control","private");
而不是打电话
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.CacheControl = "private";
不确定是否存在差异,但可能值得一试。
答案 3 :(得分:1)
重要的是要注意,实际上可以通过Acrobat Reader设置来控制显示PDF内联。
在菜单Edit > Preferences...
中,从左侧导航栏中选择Internet
,并确保选中Display PDF in browser
。
答案 4 :(得分:0)
似乎64位IE9中存在错误;如果用于要显示的PDF文件的outputStream的文件扩展名是大写的,例如'myFile.PDF'而不是像'myFile.pdf'这样的小写,outputStream的mimeType不被识别为application / pdf。它默认为mimeType文本。这种页面根本不呈现,或部分呈现或以某些不可读的字体呈现。尝试使用小写.pdf文件扩展名,以防它是大写。 祝你好运!