Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using GetJSObject to execute Javascript

Community Beginner ,
Jun 09, 2016 Jun 09, 2016

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, nLevel + 1);
}
var m = app.listMenuItems();
for ( var i=0; i < m.length; i++ ) FancyMenuList(m, 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


TOPICS
Acrobat SDK and JavaScript , Windows
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 09, 2016 Jun 09, 2016

Consider using the ExecuteThisJavascript method of the Fields collection. You set the return value by assigning it to event.value in the JavaScript that you execute. More information is in the documentation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2016 Jun 09, 2016
LATEST

As an alternative to using ExecuteThisScript, you can also install a folder level script and execute that via the JSObject. See this tutorial for more information:

Acrobat, JavaScript and VB walk into a bar... - KHKonsulting LLC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines