1

I am trying to convert a pdf to word and save it programitcally through api. I have tried the sample given in the sdk in the C# samples folder by changing the code from other refrences. However i am getting reflection error as ' Target type doesn't match' . Here is my code

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);

A dialog box is opened and file to convert will be chosen. As of i know this is a working code for many.What am i doing wrong .Please help.I have Acrobat DC installed on my system.This is my version

Version : Adobe Acrobat Pro DC 2017.009.20044

vinoth R
  • 11
  • 2
  • Since you named the variable *jsType* and pass *jsObj* as target instance object for InvokeMember, i assume you want `jsObj.GetType();` instead of `pdfd.GetType();`, or? –  May 09 '17 at 16:11
  • Why are you using reflection, especially if its a public member you have direct access to? Are you sure that the `saveAs` method exists on the `AcroPDDoc` object? – MrZander May 09 '17 at 16:12
  • i have referred the following http://stackoverflow.com/questions/11341073/how-to-convert-pdf-to-word-using-acrobat-sdk – vinoth R May 09 '17 at 17:34

1 Answers1

-1

Convert PDF to Word (.docx) using C#:

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);
}
m2pathan
  • 360
  • 2
  • 17