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

JavaScript .js Toolbar SubMenu)

Community Beginner ,
Sep 27, 2021 Sep 27, 2021

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.

TOPICS
JavaScript
983
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 ,
Sep 27, 2021 Sep 27, 2021

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

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 ,
Sep 28, 2021 Sep 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. 

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 ,
Sep 28, 2021 Sep 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
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 Beginner ,
Sep 28, 2021 Sep 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. 

 

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 ,
Sep 29, 2021 Sep 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();

 

Capture_109.png

 

Capture_108.png


Acrobate du PDF, InDesigner et Photoshopographe
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 Beginner ,
Oct 05, 2021 Oct 05, 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

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 ,
Oct 06, 2021 Oct 06, 2021
LATEST

Capture_122.png


Acrobate du PDF, InDesigner et Photoshopographe
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