【问题标题】:PDF in modal iframe renders blank in IE模态 iframe 中的 PDF 在 IE 中呈现空白
【发布时间】:2010-09-17 17:25:57
【问题描述】:

编辑 2

似乎在 Dom 中移动对象标签是问题的原因。我直接在页面上添加了一个 iframe,它工作正常,没有任何问题。

但是,当我将该 iFrame 移动到模式对话框 (http://www.ericmmartin.com/projects/simplemodal/) 中时,PDF 消失了(对象标签不再正确呈现)。

所以看来这不再是关于我的处理程序的问题,而是关于为什么在 DOM(位于 iFrame 内)中移动“对象”(或嵌入)标签会导致它“空白”的问题。 "

此外,当 pdf 从模态对话框移回其原始位置时,它会正确显示。所以,也许我应该更多地关注模态对话本身。

有什么想法?感谢您迄今为止的建议。


编辑 1

所以我为测试做了一些修改。

我有 iframe 来输出 pdf 请求的对象标记以及服务器时间。

Response.AddHeader("content-type", "text/html");
WebClient client = new WebClient();
Response.Write("<html><head></head><body><h1>"+ DateTime.Now.ToString() + "</h1><object height='100%' width='100%' name='plugin' data='" + Request.Url.ToString() + "&embed=true' type='application/pdf' /></body></html>");
Response.Flush();
Response.Close();
Response.End();

现在我正确地获得了当前时间的页面,但该对象仅在我发布 aspx 页面后第一次显示 PDF。所以这似乎是某种缓存问题?除了对象没有加载任何东西(甚至没有加载之前加载的 PDF)。

如果右键单击 iframe 并刷新页面,对象加载正常。 (如果我使用嵌入标签也是如此)。


原始问题

我知道这方面有很多问题......

但是他们要么没有得到答复,要么没有得到答复。

环境

  • .Net 4
  • Adobe 9.3.4
  • IIS 5.1
  • XP sp3
  • VS 2010
  • IE 8.0.6001.18702

背景

我正在流式传输的 pdf 来自文件没有任何扩展名的存储库(这样做是为了安全)。我在数据库中查找文件并通过以下代码将其流式传输回客户端:

Response.Clear();
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(sPath);
Response.AddHeader("content-length", buffer.Length.ToString());
Response.AddHeader("content-disposition", "inline;filename=" + fileName);
Response.AddHeader("expires", "0");
Response.AddHeader("Content-Type", "application/pdf"); //this is usually dynamic to support other types (doc, xls, txt, etc.)
Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.Flush();
Response.Close();
Response.End();

这适用于在浏览器或 iframe(显示为模式弹出窗口)中直接使用的每种文件类型(doc、txt、xls、html),pdf 的exception 文件。通过 iframe 访问时它们不能可靠地工作,但在浏览器中直接访问时工作正常。

它唯一起作用的时候是我在发布提供这些文件的 aspx 页面后第一次请求文档。所有后续点击都会返回一个空白页面(即使来自新选项卡或浏览器窗口)。 无论如何,Firefox 每次都能可靠地显示 pdf。

尝试的解决方案

我尝试了各种流式传输文件的方法:

Response.TransmitFile(sPath);
Response.WriteFile(sPath);
//As well as some others

我尝试在请求结束时将 .pdf 添加到参数中

http://www.myurl.aspx?File=test.pdf

我尝试通过添加时间戳使 URL 独一无二

http://www.myurl.aspx?File=test.pdf&Unique=Friday__September_17__2010_12_02_16_PM

未尝试

我读过有关 IIS 压缩会导致问题的信息,但它是针对较新版本的 IIS。

没有尝试使用嵌入标签,因为我想尽可能坚持使用 iFrame(现有基础设施使用它)。

任何帮助将不胜感激!!!

谢谢。

【问题讨论】:

    标签: c# internet-explorer pdf iframe simplemodal


    【解决方案1】:

    当 PDF 通过 SSL 流式传输时,我遇到了类似的问题(仅限 IE,FF 没有出现问题),只有通过执行以下操作才能解决:

    Response.ClearHeaders();
    Response.ClearContent();
    Response.Buffer = true;
    
    Response.AppendHeader("Content-Disposition", "inline; attachment; filename=Filename.pdf");
    Response.ContentType = "application/pdf";
    
    Response.WriteFile(path);
    
    Response.Flush();
    Response.End();
    

    【讨论】:

    • 谢谢,但现在我得到了相同的行为,除了文件是在本机应用程序中下载和打开的。这仍然只在我发布我的网站后第一次有效。
    【解决方案2】:

    所以我放弃了,决定改用标准的 IE 弹出窗口。

    window.open(URL, 'Window', 'height=' + pageHeight + ',width=' + pageWidth + ',top=0,left=0,resizable');
    

    我必须在一个对象标签中渲染 pdf 文件,并在弹出窗口中的 iframe 中渲染所有其他内容才能正常工作,但它可以工作......

    if (sDocType == "pdf")
    {
        Response.AddHeader("content-type", "text/html");
        WebClient client = new WebClient();
        Response.Write("<html style='margin:0px;padding:0px;'><head></head><body style='margin:0px;padding:0px;'><object height='100%' width='100%' name='plugin' data='" + Request.Url.ToString() + "&embed=true' type='" + zGetContentType(HttpContext.Current.Request.QueryString["docType"]) + "'><param name='src' value='" + Request.Url.ToString() + "&embed=true' />alt : <a href='" + Request.Url.ToString() + "&embed=true'>View</a></object></body></html>");
        Response.Flush();
        Response.Close();
        Response.End();
    }
    else
    {
        Response.AddHeader("content-type", "text/html");
        WebClient client = new WebClient();
        Response.Write("<html style='margin:0px;padding:0px;'><head></head><body style='margin:0px;padding:0px;'><iframe frameborder='0' scrolling='no' height='100%' width='100%' src='" + Request.Url.ToString() + "&embed=true' /></body></html>");
        Response.Flush();
        Response.Close();
        Response.End();
    }
    

    【讨论】:

      【解决方案3】:

      我不确定您是否需要设置文件名,尤其是在它没有 .pdf 扩展名的情况下。过去在将 PDF 流式传输到浏览器时,我一直使用以下代码:

      Response.Clear();
      Response.ContentType = "application/pdf";
      Response.BinaryWrite(pdfBuffer);
      Response.Flush();
      

      否则,客户端计算机上application/pdf CLSID 的注册表设置可能会受到影响。

      【讨论】:

      • 谢谢@AJ,我试过这个,但我得到了相同的结果。我认为问题更多是某种缓存问题(请参阅我上面的编辑)。
      【解决方案4】:

      我能够解决类似的问题(模态窗口 Internet Explorer 中的 pdf) 通过取出 iframe。相反,将 pdf 加载到 html 对象元素中。 请看下面的链接:

      http://intranation.com/test-cases/object-vs-iframe/

      总结一下: 无效的设置:

      jQuery floatbox,用 iframe 加载 html 片段,将 aspx 页面加载到 iframe,将 pdf 加载到 aspx 页面中

      现在可以使用的设置:

      jQuery 浮动框,加载 html 片段,附加对象元素。 在附加对象元素之前,设置数据 对象元素的属性到 aspx 页面 url

      【讨论】:

        猜你喜欢
        • 2011-05-25
        • 2016-05-29
        • 1970-01-01
        • 2021-10-13
        • 2018-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多