2 Replies Latest reply on Jun 9, 2016 4:21 AM by Karl Heinz Kremer

    Using GetJSObject to execute Javascript


      I often use Acrobat automation in Delphi applications I write, usually without any problem.


      At the moment, I'm trying to write a Delphi application to assist other developers retrieve the list of menu item names available to use with CAcroApp.ExecuteMenuItem.


      So far, I've found this script which gets a list of menu item names


      function FancyMenuList(m, nLevel)
      var s = "";
      for (var i = 0; i < nLevel; i++) s += " ";
      console.println(s + "+-" + m.cName);
      if ( m.oChildren != null )
      for ( var i = 0; i < m.oChildren.length; i++ )
      FancyMenuList(m.oChildren[i], nLevel + 1);
      var m = app.listMenuItems();
      for ( var i=0; i < m.length; i++ ) FancyMenuList(m[i], 0);


      and I can execute that by hand (in the Acrobat gui) in the JS console window fine, and copy the output to the clipboard.


      What I'd like do do is to run the script and retrieve its output back into my Delphi app, and that's where I'm  stuck.


      I can successfully call GetJSObject() from a CAcroPDDoc and call the methods of the various Acrobat JS objects listed in the JavaScript™ for Acrobat® API Reference.  What I have not been able to find, though, is to use GetJSObject to execute an arbitrary script such as the one above and retrieve the output programatically.  I noticed that in the Api Reference there is an example of using Console.PrintLn to execute a script, but I can't see any obvious way of retrieve the resulting console window output.  Any suggestions?


      I'm using Acrobat 8, btw.


      TIA, Martyn