Skip to main content
vinothr61045810
Participating Frequently
May 9, 2017
Question

not able call 'Saveas' function to save pdf as word through acrobat. throws reflection exception.

  • May 9, 2017
  • 6 replies
  • 4273 views

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

                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

This topic has been closed for replies.

6 replies

Legend
May 10, 2017

The interface you are trying to use, based on jsobject, you will see from the documentation is the Visual Basic -JavaScript bridge. Really determined people who understand VB, OLE, C# and JavaScript really well have been able to twist the interface to work with C# instead.  Are you that experienced and determined? If not, please consider writing in VB instead.

Legend
May 10, 2017

You are trying to squeeze C# functionality out of a VB interface. To reduce pain, consider using VB.

vinothr61045810
Participating Frequently
May 10, 2017

could you please be more elaborate.

vinothr61045810
Participating Frequently
May 10, 2017

I have already enabled it. Even after enabling from preferences run button is still disabled. I don't know what else i need to do. One more thing i noticed is AcroPDDoc dll does not contain 'saveAs' method. Any help?

Bernd Alheit
Community Expert
Community Expert
May 10, 2017

Enter the code in the debugger and press ctrl-a and ctrl-enter

Legend
May 10, 2017

Don't use the run button.

vinothr61045810
Participating Frequently
May 10, 2017

Javascript run is disabled

Bernd Alheit
Community Expert
Community Expert
May 10, 2017

Enable it in the preferences.

vinothr61045810
Participating Frequently
May 10, 2017

How can i do that? when i try to run some js code JS run option is disabled

Bernd Alheit
Community Expert
Community Expert
May 10, 2017

Start the debugger with ctrl-j and use the saveAs method.

Bernd Alheit
Community Expert
Community Expert
May 9, 2017

What happens when you try it with the JavaScript debugger in Acrobat?