Skip to main content
Participant
October 25, 2022
Answered

How to use java to export file

  • October 25, 2022
  • 1 reply
  • 653 views

I want to draw and export the file by manipulating com components in java, but I get an error when exporting. Example code and error are as follows:

 

code:

ActiveXComponent app = new ActiveXComponent("Illustrator.Application");
Dispatch.call(app, "open","D:\\pic\\ai\\init.ai").toDispatch();
Dispatch doc = Dispatch.get(app, "activeDocument").toDispatch();
Dispatch.call(doc, "exportFile", "D:\\test2.dwg",7);

 
error:

Exception in thread "main" com.jacob.com.ComFailException: Can't map name to dispid: exportFile
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at com.jacob.com.Dispatch.callN(Dispatch.java:453)
at com.jacob.com.Dispatch.call(Dispatch.java:541)

 

This topic has been closed for replies.
Correct answer 赵2669500597ir

For somone else having the same issue, please be kind to share what the correct name of the method is.

-Manan


The correct name of the method is "export".

1 reply

Community Expert
October 25, 2022

Hi @赵2669500597ir,

The error suggests that probably the method name is not correct. I don't have access to a WIN machine but I have seen that the method names in JS interface and COM interface are not always the same. So the first thing to check would be the COM interface and double check the method name

-Manan

-Manan
Participant
October 25, 2022

Yes, I just found the wrong way to name it. Thank you for your answer

Community Expert
October 25, 2022

For somone else having the same issue, please be kind to share what the correct name of the method is.

-Manan

-Manan