Skip to main content
Participating Frequently
September 28, 2021
Question

JavaScript .js Toolbar SubMenu)

  • September 28, 2021
  • 5 replies
  • 963 views

Hi All -

I've put the following code (credit: http://khkonsulting.com/2009/03/counting-bookmarks/) in C:\Users\jxxxx\AppData\Roaming\Adobe\Acrobat\Privileged\DC\JavaScripts\bookmark.js

function CountBookmarks(bkm, nLevel)
{
    var count = 0;
    if (bkm.children != null)
    {
        count = bkm.children.length;
        for (var i = 0; i < bkm.children.length; i++)
        {
             count += CountBookmarks(bkm.children[i], nLevel + 1);
        }
    }

    return count;
}


function DoIt()
{
    console.clear(); console.show();
    var n = CountBookmarks(this.bookmarkRoot, 0);
    console.println("Number of bookmarks found: " + n);
}



// add the menu item
app.addMenuItem({
     cName: "countBookmarks",
     cUser: "Count Bookmarks",
     cParent: "Tools",
     cExec: "DoIt();",
     cEnable: "event.rc = (event.target != null);"
});

For the life of me I can't figure out where the subMenu item is . . . what is "Tools" cParent? Where can I locate the dang button to test it.....

Thanks in advance.

This topic has been closed for replies.

5 replies

JR Boulay
Community Expert
Community Expert
October 6, 2021

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
Community Expert
September 29, 2021

You can use this modified script in an Action or in a Custom Command.

Actions and Custom Commands can be placed as icon in the QuickTools bar.

 

function CountBookmarks(bkm, nLevel) {
var count = 0;
if (bkm.children != null) {
count = bkm.children.length;
for (var i = 0; i < bkm.children.length; i++) {
count += CountBookmarks(bkm.children[i], nLevel + 1);
}
}

return count;
}


function DoIt() {
console.clear(); console.show();
var n = CountBookmarks(this.bookmarkRoot, 0);
console.println("Number of bookmarks found: " + n);
}

 

DoIt();

 

 

Acrobate du PDF, InDesigner et Photoshopographe
Joel5D89Author
Participating Frequently
October 5, 2021

Hi All -

Thank you for the help. I actually was able to get past that hurdle and have now created a mostly functional ToC script to pull bookmarks into a ToC.  Couple shortfalls right now - one of which is it's only good for up to 1 page of bookmarks (about 50 or so bookmarks) but that'll be fixed shortly.

 

Full script can be found here: GOOGLE DRIVE - BOOKMARKS TO TABLE OF CONTENTS

JR Boulay
Community Expert
Community Expert
September 28, 2021

Replace this line:

cParent: "Tools",

 

By this line:

cParent: "Edit",

 

The Tools menu no longer exists since Acrobat X.

 

 

 

Acrobate du PDF, InDesigner et Photoshopographe
Joel5D89Author
Participating Frequently
September 28, 2021

Perfect. That did the trick. 

 

I guess as a side question - if (I haven't decided) I wanted to make this an icon in one of the toolbars . . . how would I go about doing that? I wouldn't want it in the "add on" toolbar because then my co-workers would have to go out of their way to enable that. 

 

Thanks again. I'll be back with a lot of questions about this project I've taken on. Unfortunately, seems like a lot of the guides and documentation is outdated (and definitely not written for someone who dabbles in coding.....I've learned basics of Python, VBA, C#, and a few others . . . all have pretty "newbie" guides and tutorials, I haven't found anything similar for javascript in Adobe DC. 

 

Legend
September 28, 2021

Bear in mind the "menu" is the bar at the top with File, Edit etc. Some people call the bar at the right side a "menu" but it isn't. Some people call the bar if icons below the menu a menu, but that is t either. 

Bernd Alheit
Community Expert
Community Expert
September 28, 2021

Change "Tools" to "File". Then you can see the menu entry under File.