C# 无法呼叫';Saveas';函数通过acrobat将pdf另存为word。引发反射异常
我正在尝试将pdf转换为word,并通过api编程保存它。我尝试了sdk中C#samples文件夹中给出的示例,方法是从其他参考中更改代码。但是,由于“目标类型不匹配”,我得到了反射错误。这是我的密码C# 无法呼叫';Saveas';函数通过acrobat将pdf另存为word。引发反射异常,c#,asp.net,adobe,acrobat,acrobat-sdk,C#,Asp.net,Adobe,Acrobat,Acrobat Sdk,我正在尝试将pdf转换为word,并通过api编程保存它。我尝试了sdk中C#samples文件夹中给出的示例,方法是从其他参考中更改代码。但是,由于“目标类型不匹配”,我得到了反射错误。这是我的密码 AcroPDDoc pdfd = new AcroPDDoc(); pdfd.Open(filename);[enter image description here][1] Object jsObj = pdfd.GetJSObject(); Type jsType = pdfd.GetType
AcroPDDoc pdfd = new AcroPDDoc();
pdfd.Open(filename);[enter image description here][1]
Object jsObj = pdfd.GetJSObject();
Type jsType = pdfd.GetType();
//have to use acrobat javascript api because, acrobat
object[] saveAsParam = { "newFile.docx", "com.adobe.acrobat.docx", "",
false, false };
jsType.InvokeMember("saveAs", BindingFlags.InvokeMethod |
BindingFlags.Public | BindingFlags.Instance, null, jsObj, saveAsParam,
CultureInfo.InvariantCulture);
将打开一个对话框,并选择要转换的文件。据我所知,这是一个适用于许多人的工作代码。我做错了什么。请帮助。我的系统上安装了Acrobat DC。这是我的版本
版本:Adobe Acrobat Pro DC 2017.009.20044使用C#将PDF转换为Word(.docx):
因为您命名了变量jsType并将jsObj作为InvokeMember的目标实例对象传递,所以我假设您想要
jsObj.GetType()
而不是pdfd.GetType()代码>,或者?为什么要使用反射,尤其是如果它是您可以直接访问的公共成员?您确定AcroPDDoc
对象上存在saveAs
方法吗?我已经参考了以下内容
AcroPDDoc() pdfDoc = new AcroPDDoc();
if (pdfDoc.Open(sourceFileName))
{
Object jsObj = pdfDoc.GetJSObject();
Type type = jsObj.GetType();
object[] saveAsParam = { convertedFilePath, "com.adobe.acrobat.docx" };
type.InvokeMember(
"saveAs",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, jsObj, saveAsParam);
}