使用 PDF 填充 Iframe - 使用 MVC [IE 问题]
目前,我在使用 PDF 文档填充 iframe 时遇到问题,但此问题仅出现在 IE 中。
基本布局:
我有一个屏幕,其中包含项目(附件)列表,可以是图像、文本或 pdf。当用户单击这些项目之一时,它将调用控制器操作 [ViewAttachment],该操作将返回请求的项目并将其显示在 iframe 中。
目前,这适用于除 IE 中的 PDF 之外的所有数据类型。 (Firefox、Chrome等都在iframe中显示PDF没有问题。)
我之前使用的是Adobe Reader 9,最近升级到10希望解决这个问题。我将附上一些代码,看看是否有人对如何解决此问题有任何建议。
填充 iframe 的代码:(为了便于阅读,移至两行)
$(".viewattachment").live('click',function ()
{
$("iframe#test").attr("src","<%=Url.Action("ViewAttachment","Images") %>?
attachment=" + $(this).next().val());
});
ViewAttachment 控制器操作:
public ActionResult ViewAttachment(string attachmentGuid)
{
Attachment attachment= imageAgent.GetAttachment(attachmentGuid);
Stream resultStream = new MemoryStream();
resultStream = StorageProviders[attachment.ProviderName]
.ReadFile(attachment.FileReference);
resultStream.Position = 0;
FileStreamResult result = new FileStreamResult(resultStream,
attachment.ContentType);
return result;
}
注释:
- 我尝试切换“在以下位置显示 PDF” : Adobe Reader 中的“浏览器”没有任何成功。
- 目前正在针对 IE8 进行测试。
- 单击 PDF 进行查看时,iframe 只会保留其之前的内容,根本不会发生变化。
Currently, I have an issue with populating an iframe that I have with a PDF document, but this issue only occurs in IE.
Basic Layout:
I have a screen that contains a list of items (attachments), which can be images, text or pdf. When the user clicks on one of these items - it will make a call to a controller action [ViewAttachment] which will return the requested item and display it in the iframe.
This currently works for all data types with the exception of PDFs in IE. (Firefox, Chrome etc. all display the PDF in the iframe without issue.)
I previously was using Adobe Reader 9, and recently upgraded to 10 in hopes of solving this issue. I'll attach some code to see if anyone has any suggestions as to how to possibly resolve this.
Code to Populate iframe: (Moved to two lines for readability)
$(".viewattachment").live('click',function ()
{
$("iframe#test").attr("src","<%=Url.Action("ViewAttachment","Images") %>?
attachment=" + $(this).next().val());
});
ViewAttachment Controller Action:
public ActionResult ViewAttachment(string attachmentGuid)
{
Attachment attachment= imageAgent.GetAttachment(attachmentGuid);
Stream resultStream = new MemoryStream();
resultStream = StorageProviders[attachment.ProviderName]
.ReadFile(attachment.FileReference);
resultStream.Position = 0;
FileStreamResult result = new FileStreamResult(resultStream,
attachment.ContentType);
return result;
}
Notes:
- I've attempted toggling the "Display PDF in Browser" in Adobe Reader without any success.
- Currently testing this for IE8.
- When clicking on a PDF to view - the iframe simply remains at it's previous content and doesn't change at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
经过几种不同的方法和迭代测试后,我确定这是 IE8-9 和 Adobe Reader 9-10 版本之间的冲突。我将以下元标记添加到包含 iframe 的窗口中,它解决了所有问题:
这至少应该在进行更新/修复之前有效。
After several different methods and iterations of testing - I determined that it was a conflict between IE8-9 and versions of Adobe Reader 9-10. I added the following meta tag to the window containing the iframe and it resolved all of the issues:
This should at least work until an update / fix is made.
您是否尝试过直接点击 pdf 网址?如果它在浏览器中加载,那么您可以将问题范围缩小到 iframe。如果弹出 Adobe Reader,则说明 IE 插件有问题。
Have you tried hitting the pdf url directly? If it loads within the browser, then you can narrow down the problem to the iframe. If Adobe Reader pops up, then you know its a problem with the IE Plugin.
我在使用 spring mvc 时遇到了同样的问题。我透露,如果我将 iframe 放入某个标签(如“util:panel”)中,iframe 不会在 IE 8 中加载 pdf 内容。当我将 iFrame 放在标签之外时,一切正常。
I had the same problem working with spring mvc. I releazed that if I put the Iframe inside some tag, like 'util:panel', the iframe does not load de pdf content in IE 8. When I put the iFrame out of the tag, all work fine.