C# WebBrowser 不会显示嵌入对象
这可能是一个愚蠢的问题,但我就是无法让它发挥作用。我正在尝试将 pdf 文件嵌入到 ac# 程序中的网络浏览器中。简单吧?我是这么想的,但事实证明并非如此。 这是 html 代码:
<object classid="" type="application/pdf" width="400" height="300" id="pdf1">
<param name="src" value="Test.pdf" />
<div style="text-align:center; color:#CCCCCC" >No Preview Available.</div>
</object>
这就是 html 文件中的全部内容。有趣的是,这在 IE 中完美运行(据我所知,这是 Web 浏览器使用的)。我尝试以 non-IE
方式实现对象标记,使用 src 属性等等,但它做了同样的事情。发生的情况是 WebBrowser 控件仅显示 No Preview available
,这意味着 pdf 未成功嵌入。这是c#代码:
wbPreview.Navigate("I:/Documents/Visual Studio 2008/Projects
/PlanReferenceDatabase/test.html");
有人能告诉我为什么c#中的网络浏览器无法显示pdf,但其他浏览器可以吗?
This may be a dumb question, but I just can't get it to work. I'm trying to embed a pdf file into a webbrower in a c# program. Simple right? I thought so, but it proved otherwise.
Here's the html code:
<object classid="" type="application/pdf" width="400" height="300" id="pdf1">
<param name="src" value="Test.pdf" />
<div style="text-align:center; color:#CCCCCC" >No Preview Available.</div>
</object>
And that's all thats in the html file. The funny thing is, this works perfectly in IE (which as I understand is what the WebBrowser uses). I've tried implementing the object tag the non-IE
way, with an src attribute and whatnot, but it did the same thing. What's happening is the WebBrowser control is just displaying No Preview Available
meaning that the pdf was not successfully embedded. Here's the c# code:
wbPreview.Navigate("I:/Documents/Visual Studio 2008/Projects
/PlanReferenceDatabase/test.html");
Can someone tell me why the web browser in c# cannot display the pdf, but the other browser can?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试像这样格式化标签:
在标签中包含数据属性,它似乎工作得很好 - 刚刚在 IE8 / IE9 机器上的浏览器控件中尝试了这个,它显示为内联。
Try formatting the tag like this:
Include the data attribute in the tag and it seems to work just fine - just tried this in my browser control on a IE8 / IE9 machine and it displays inline.
我解决了我的问题。以防万一其他人也有同样的情况,这就是我所做的:
首先,我将 Visual Studio 中“构建”选项卡下的“目标平台”属性设置为 x86,因为事实证明,64 位 IE 无法渲染 PDF。
其次,我使用嵌入标记而不是对象标记,因为 IE 要求您使用“classid”以及在使用对象标记时不需要的各种 Active X 内容。
I solved my problem. Just in case anyone else has the same one, here's what I did:
First I set the "target platform" property under the build tab in visual studio to x86 because as it turns out, 64bit IE can't render PDFs.
Second I used the embed tag instead of the object tag, because IE requires you to use "classid" and all sorts of Active X stuff you don't want when you use the object tag.