尝试使用AxAcroPDFLib打开PDF

我在我的电脑上安装了最新的Adobe Reader(Adobe Acrobat Reader DC)。 现在我想在C#中使用AxAcroPDFLib来打开并在我的Windows窗体应用程序中显示PDF文件。

问题是,如果我尝试使用LoadFile()方法,那么它表示此方法不存在。

我将Adobe Acrobat 7.0 Browser Control Type Library 1.0 COM引用加载到我的项目中,并将Adobe PDF Reader COM组件添加到我的工具箱(Tools / Choose Toolbox Items … / COM Components)。

在此处输入图像描述

怎么了? 我该如何用这个库打开PDF文件? 我在互联网上发现了很多教程,每个人都告诉我必须使用LoadFile方法…请帮忙,谢谢!

Adobe Reader DC不再支持此function。 安装Adobe Reader v11,它将工作。

这仍然是可能的。 您只需要以不同方式调用该方法。

 public void LoadFile(string path) { this.GetOcx().GetType().InvokeMember("LoadFile", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, this.GetOcx(), new object[1] { path }); } 

有关详细信息,请参阅此帖

将表示您的控件(类型为AcroPDFLib.IAcroAXDocShim )的对象转换为AcroPDFLib.IAcroAXDocShim接口:

 var acro = (AcroPDFLib.IAcroAXDocShim)axAcroPDFControl.GetOcx(); acro.LoadFile(fileName); 

现在看来,所有有用的方法都可以在此界面下使用。 如果安装了Adobe Reader DC,则可以使用。

可以定义一点扩展:

 public static class AcroExtensions { public static AcroPDFLib.IAcroAXDocShim AsAcroPDF(this AxAcroPDFLib.AxAcroPDF source) { return (AcroPDFLib.IAcroAXDocShim)source.GetOcx(); } } 

然后你可以写:

 axAcroPDFControl.AsAcroPDF().LoadFile(fileName) 

以防任何人仍需要解决方案。 我正在使用Adobe Acrobat DC,实际上有AxAcroPDF.LoadFile()方法。 但是,它不起作用,即没有任何事情发生:/

所以,我使用AxAcroPDF.src属性和url作为本地文件

 axAcroPdf1.src = "file:///c:/my.pdf" 

希望能帮助到你