模式 iframe 中的 PDF 在 IE 中呈现空白
编辑2
看来在Dom中移动对象标签是问题的原因。我直接在页面中添加了一个 iframe,它工作正常,没有任何问题。
但是,当我将该 iFrame 移动到模式对话框中时 (http://www.ericmmartin.com/ items/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 文件。通过 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(现有基础设施使用它)。
任何帮助将不胜感激!!!
谢谢。
EDIT 2
It appears that moving the object tag in the Dom is the cause of the problem. I added an iframe directly to the page and it works fine without any problems.
However, when I move that iFrame into a modal dialogue box (http://www.ericmmartin.com/projects/simplemodal/) the PDF disappears (the object tag no longer renders correctly).
So it appears that it's no longer a question about my handler, but more a question about why moving the "object" (or embed) tag in the DOM (which lives inside an iFrame) causes it to "blank-out."
Also, when the pdf is moved from the modal dialogue back to its original position, it appears correctly. So, perhaps I should focus more on the modal dialogue itself.
Thoughts? Thanks for your suggestions thus far.
EDIT 1
So I've made some modifications for testing.
I've got the iframe to output an object tag for pdf requests along with the server time.
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();
Now I get a page with the current time correctly, but the object only displays the PDF the first time after I publish the aspx page. So it appears to be some sort of caching issue? Except that the object isn't loading anything (not even the previously loaded PDF).
If right click on the iframe and refresh the page, the object loads up fine. (The same is true if I use an embed tag).
Original Question
I know there are a lot of questions on this...
- streaming PDF data through an ASPX page
- Server generated PDF not displaying in IFrame on aspx page on some (but not all )PCs
- Displaying a PDF Document in ASP.net page
But they either weren't answered, or the answer didn't work.
Environment
- .Net 4
- Adobe 9.3.4
- IIS 5.1
- XP sp3
- VS 2010
- IE 8.0.6001.18702
Background
The pdf's I'm streaming come from a storage repository where the files don't have any extensions (this is done for security). I look up the file in the database and stream it back to the client via the following code:
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();
This works for every file type (doc, txt, xls, html) when used directly in the browser or in the iframe (displayed as a modal popup) with the exception of pdf files. They do not work reliably when accessed via the iframe, but work fine when accessed directly in the browser.
The only time it does work is the first time I request a document after I publish the aspx page that is serving these files. All subsequent hits return a blank page (even from new tabs or browser windows). Firefox reliably displays the pdf every time regardless.
Attempted Solutions
I've tried various ways I of streaming the file:
Response.TransmitFile(sPath);
Response.WriteFile(sPath);
//As well as some others
I've tried adding .pdf to a parameter at the end of the request
http://www.myurl.aspx?File=test.pdf
I've tried making the URL unique by adding a time stamp
http://www.myurl.aspx?File=test.pdf&Unique=Friday__September_17__2010_12_02_16_PM
Un-Attempted
I've read about IIS compression causing problems, but it was for a newer version of IIS.
Didn't try using embed tag since I would like to stick to the iFrame if possible (The existing infrastructure uses it).
Any help would be greatly appreciated!!!
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当 PDF 通过 SSL 传输时(仅限 IE,FF 没有出现该问题),我遇到了类似的问题,只能通过执行以下操作来解决:
I had a similar problem that arose when the PDFs were streaming over SSL (IE only, FF didn't exhibit the issue) that was only solved by doing the following:
所以我放弃了,决定使用标准的 IE 弹出窗口来代替。
我必须在对象标签中渲染 pdf 以及弹出窗口内 iframe 内的所有其他内容才能使其工作,但它工作......
So I gave up and decided to use a standard IE popup window instead.
I had to render the pdfs in an object tag and everything else inside an iframe within the popup for it to work, but it works...
我不确定您是否需要设置文件名,特别是如果它没有 .pdf 扩展名。过去,当将 PDF 流式传输到浏览器时,我总是使用此代码:
否则,客户端计算机上的
application/pdf
CLSID 的注册表设置可能会受到某些影响。I'm not sure that you need to set the filename, especially if it doesn't have the .pdf extension. When streaming PDFs to browser in the past, I've always used this code:
Otherwise, there's a possibility that something has hosed over the registry settings for the
application/pdf
CLSID on the client computer.我能够解决类似的问题(模式窗口 Internet Explorer 内的 pdf)
通过取出 iframe。相反,将 pdf 加载到 html 对象元素中。
请参阅下面的链接:
http://intranation.com/test-cases/object-vs -iframe/
总结一下:
不起作用的设置:
jQuery floatbox,使用 iframe 加载 html 片段,将 aspx 页面加载到 iframe,将 pdf 加载到 aspx 页面
现在有效的设置:
jQuery floatbox,加载 html 片段,附加对象元素。
在附加对象元素之前,设置数据
对象元素的属性到 aspx 页面 url
I was able to solve a similar problem (pdf inside of modal window internet explorer)
by taking out the iframe. Instead, load the pdf into an html object element.
see the link below:
http://intranation.com/test-cases/object-vs-iframe/
To sum it up:
The setup that did not work:
jQuery floatbox, loads html fragment with iframe, load aspx page into iframe, load pdf into aspx page
The setup that now works:
jQuery floatbox, loads html fragment, append object element.
before appending the object element, set data
attribute of object element to the aspx page url