简体   繁体   English

C#IE插件BHO获取pdf

[英]c# IE Plugin BHO get the pdf

I need help for a little IE Plugin (Browser Helper Object). 我需要一些IE插件(浏览器帮助器对象)的帮助。

What the Plugin should do: 插件应该做什么:

If the user clicks on a link with pdf behind, the plugin should call an exe file installed on the computer. 如果用户单击后面带有pdf的链接,则插件应调用计算机上安装的exe文件。 The exe file would check the PDF and open the default pdf application or a special one. exe文件将检查PDF并打开默认的pdf应用程序或特殊的pdf应用程序。

What i have done: 我做了什么:

My BHO starts with my IE. 我的BHO从我的IE开始。 I used this code for the beginning: 我最初使用此代码:
http://www.codeproject.com/Articles/19971/How-to-attach-to-Browser-Helper-Object-BHO-with-C http://www.codeproject.com/Articles/19971/How-to-attach-to-Browser-Helper-Object-BHO-with-C
I disabled all adobe plugins so the ie download window shows up. 我禁用了所有adobe插件,因此显示了“下载”窗口。 Whit this code i can parse the html body add html markup etc. but thats not what i'm trying to do... 惠特这段代码我可以解析html正文添加html标记等,但这不是我想要做的...

My Problem: 我的问题:

I don't know how to grab the pdf. 我不知道如何获取PDF。 If i call directly a pdf download link the cast of the site object into a InternetExplorer or WebBrowser Object fails. 如果我直接调用pdf下载链接,则将站点对象转换为InternetExplorer或WebBrowser对象失败。

 public int SetSite(object site) { if (site != null) { ieInstance = site as InternetExplorer; ieInstance.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else if (ieInstance != null) { ieInstance.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } return 0; } 

Document = '((SHDocVw.InternetExplorer)(ieInstance)).Document' threw an exception of type 'System.Runtime.InteropServices.COMException' Document ='(((SHDocVw.InternetExplorer)(ieInstance))。Document'引发了类型为'System.Runtime.InteropServices.COMException'的异常

Could someone tell me, how i can grab the pdf befor the download window in the IE appears? 有人可以告诉我,在IE中出现下载窗口之前,我该如何获取pdf? I know there is a Event before download, but also this event don't help me. 我知道下载前会有一个事件,但是这个事件对我没有帮助。

What are you trying to achieve more broadly? 您想更广泛地实现什么?

You can't grab a HTML document instance when the browser is showing a PDF file because there isn't one-- the PDF object is loaded instead of the HTML-rendering object. 当浏览器显示PDF文件时,您将无法获取HTML文档实例,因为没有一个实例–加载了PDF对象而不是HTML呈现对象。

Depending on what you're trying to achieve, there are likely better ways to accomplish it (most likely by registering a MIME Filter for the application/pdf MIME type). 根据您要实现的目标,可能有更好的方法来实现它(最有可能的方法为application / pdf MIME类型注册MIME筛选器 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM