3 Replies Latest reply on Dec 8, 2011 1:45 PM by MarkWalsh

    How to strip out certain words from Acrobat bookmarks?

    Mauzilator

      How would I go about creating javascript code that stripped out the word "Chapter" and the subsequent chapter number from bookmark headings?

       

       

      For example, the top-level chapters in my book always print out in bookmarks this way:

       

       

                Chapter 1 [name of chapter]

                Chapter 2 [name of chapter]

       

       

      I just want the bookmarks to read:

       

       

                [name of chapter]

                [name of chapter]

       

       

      To make this a bit more complicated, I'm already using javascript that strips out leading numbers from certain bookmarks. So for example, certain bookmarks will publish:

       

       

                1.1 [name of heading]

                          1.2.1 [name of heading]

       

       

      ... and my javascript will change those to:

       

       

                [name of heading]

                          [name of heading]

       

       

      Here's my current javascript:

       

       

      function removeBookmarkPrefix(bookmark) {    

      // If there are no bookmarks, do nothing

          if (bookmark == null) return;

      // Resursive function to remove bookmark prefix    

      // Rename bookmark without prefix

          bookmark.name = bookmark.name.replace(/^\d\S*\s+/, "");    

      if (bookmark.children != null) {

              for (var i = 0; i < bookmark.children.length; i++) {

                   removeBookmarkPrefix(bookmark.children[i]);         }

          }

       

       

       

       

      I'd like to add more code to strip out the word "Chapter" and any subsequent numbering.