Trying to open a PDF with AxAcroPDFLib

一曲冷凌霜 提交于 2019-12-06 07:44:22

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

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

Scott

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.

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)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!