JavaScript .js Toolbar SubMenu)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Change "Tools" to "File". Then you can see the menu entry under File.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Replace this line:
cParent: "Tools",
By this line:
cParent: "Edit",
The Tools menu no longer exists since Acrobat X.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied

