Trying to open a PDF with AxAcroPDFLib

2019-05-22 00:28发布

I have installed the latest Adobe Reader on my PC (Adobe Acrobat Reader DC). Now I would like to use AxAcroPDFLib in C# to open and show a PDF file in my Windows Forms application.

The problem is, if I am trying to use the LoadFile() method, then it says that this method is not exist.

I loaded the Adobe Acrobat 7.0 Browser Control Type Library 1.0 COM reference into my project, and I added the Adobe PDF Reader COM Component to my toolbox (Tools / Choose Toolbox Items... / COM Components).

enter image description here

What is wrong? How should I open a PDF file with this library? I found a lot of tutorials on the internet, and everybody tells that I have to use the LoadFile method... Please help, thanks!

标签: c# pdf adobe
4条回答
混吃等死
2楼-- · 2019-05-22 00:40

This is no longer supported in Adobe Reader DC. Install Adobe Reader v11 and it will work.

查看更多
放荡不羁爱自由
3楼-- · 2019-05-22 00:41

Cast object representing your control (of type AxAcroPDFLib.AxAcroPDF) to AcroPDFLib.IAcroAXDocShim interface:

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

It appears that all useful methods are now available under this interface. Works if Adobe Reader DC is installed.

A little extension can be defined:

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

Then you can write:

axAcroPDFControl.AsAcroPDF().LoadFile(fileName)
查看更多
Root(大扎)
4楼-- · 2019-05-22 00:42

Just in case anyone still needs a solution. I'm using Adobe Acrobat DC and actually have AxAcroPDF.LoadFile() method. However, it doesn't work i.e. nothing happenns :/

So, I used AxAcroPDF.src property with url for local file

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

Hope it helps

查看更多
祖国的老花朵
5楼-- · 2019-05-22 01:00

This is still possible. You just need to invoke the method differently.

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

See this post for details.

查看更多
登录 后发表回答