开发者

Populating Iframe with PDF - Using MVC [IE Issue]

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 Mem开发者_C百科oryStream();
      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.


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:

<meta http-equiv="X-UA-Compatible" content="IE=7" />

This should at least work until an update / fix is made.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜