Skip to main content
vinothr61045810
Participating Frequently
May 9, 2017 10:48 AM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

17 replies

Legend
May 10, 2017 4:14 PM UTC

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.

Translate
Legend
May 10, 2017 2:06 PM UTC

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

Translate
vinothr61045810
Participating Frequently
May 10, 2017 2:18 PM UTC

could you please be more elaborate.

Translate
vinothr61045810
Participating Frequently
May 10, 2017 11:35 AM UTC

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?

Translate
Bernd Alheit
Community Expert
Community Expert
May 10, 2017 12:58 PM UTC

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

Translate
Legend
May 10, 2017 1:06 PM UTC

Don't use the run button.

Translate
vinothr61045810
Participating Frequently
May 10, 2017 10:54 AM UTC

Javascript run is disabled

Translate
Bernd Alheit
Community Expert
Community Expert
May 10, 2017 11:18 AM UTC

Enable it in the preferences.

Translate
vinothr61045810
Participating Frequently
May 10, 2017 10:39 AM UTC

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

Translate
Bernd Alheit
Community Expert
Community Expert
May 10, 2017 10:51 AM UTC

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

Translate
Bernd Alheit
Community Expert
Community Expert
May 9, 2017 6:25 PM UTC

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

Translate