4 Replies Latest reply on Jul 13, 2015 2:53 PM by Shawnny Canuck

    Rename Bookmarks Using JavaScript?

    Shawnny Canuck

      Hello all,

       

      I have searched the internet and Adobe forums and I cannot find an answer for this. Is it possible to rename a bookmark using JavaScript? I want to run a batch rename on my bookmarks to change/replace employee numbers to employee names. For example:

       

      12345678 --> John Doe

       

      I have to do this on a large amount of files that contain a lot of employee numbers and that is why I am looking at a JavaScript solution. Thanks everyone for your help.

        • 1. Re: Rename Bookmarks Using JavaScript?
          try67 MVP & Adobe Community Professional

          Yes, in Acrobat you can rename bookmarks using a script. It's not possible if you only have the free Reader, though.

          The way you do it is you access the Bookmark object in question and change the value of its name property.

          For example, this code will change the name of the first bookmark in the list to "John Doe":

           

          this.bookmarkRoot.children[0].name = "John Doe";

           

          If you have a list of all employee names and matching numbers then this task can be automated in its entirety using a script.

          • 2. Re: Rename Bookmarks Using JavaScript?
            Shawnny Canuck Level 1

            Hi Try,

             

            Thanks for your reply. I have the latest version of Adobe XI Pro. What would be the best approach referencng a text or Excel file to pull data from and replace or to just hard code everything and replace that way? I hope that makes sense I am new to all of this and teaching myself as I go. Thanks again.

            • 3. Re: Rename Bookmarks Using JavaScript?
              try67 MVP & Adobe Community Professional

              There are various ways you can read an external file. It can be done using a DataObject or even using util.readFileIntoStream(), if the file is not too long.

              Once you have the file's contents as a string you'll need to process that string, split it by lines and then split each line to get the data you need in a usable format.

              Then you would need to traverse the bookmarks tree, comparing each item in it to the values in the list from the text file, and renaming it if it's a match.

              If the bookmarks tree is not flat (ie, it has sub-bookmarks) then you would need to use a recursive method to traverse it.

              This is not a simple project for a beginner...

              • 4. Re: Rename Bookmarks Using JavaScript?
                Shawnny Canuck Level 1

                OK as you stated it sounds complicated but I am willing to try or maybe just pay someone to do it for me. This project isn't rush so I don't need a solution right away I can chip away at it. Thanks for everything Try I appreciate it.