Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Change all bookmarks to title case
  FAQ FAQ  Forum Search   Register Register  Login Login

Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Change all bookmarks to title case

 Post Reply Post Reply
Author
oald View Drop Down
Member
Member


Joined: 16 Sep 2011
Points: 42
Post Options Post Options   Quote oald Quote  Post ReplyReply Direct Link To This Post Topic: Change all bookmarks to title case
    Posted: 26 Nov 2013 at 8:08am
Hello, I need to:
1. Change 1st level bookmarks to UPPER CASE;
My Product Information:
Acrobat Pro 8.1.6, Windows
Back to Top
oald View Drop Down
Member
Member


Joined: 16 Sep 2011
Points: 42
Post Options Post Options   Quote oald Quote  Post ReplyReply Direct Link To This Post Posted: 26 Nov 2013 at 8:24am

Hello, I need to:

1. Change 1st level bookmarks to UPPER CASE;

2. Change all other bookmarks to Title Case;

3. Change all function word less than 5 letters (e.g. an, the, as, at, but) to lower case;

4. Leave the case of scientific terms (e.g. GMP, cGMP, HPLC, HBsAb, HBsAg) as is.

 

I work out the following code which can complete the first 3 points but cannot realize point 4, anyone can help me? Thanks so much!

 

       //Define a method to change sentence to Title Case

       String.prototype.toTitleCase = function()

       {

         var smallWords = /^(a|an|and|as|at|but|by|en|from|into|off|onto|over|than|with|but||for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;

         return this.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, index, title)

         {

           if (index > 0 && index + match.length !== title.length &&

             match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" &&

             (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &&

             title.charAt(index - 1).search(/[^\s-]/) < 0)

           {

             return match.toLowerCase();

           }

           if (match.substr(1).search(/[A-Z]|\../) > -1)

           {

             return match;

           }

           return match.charAt(0).toUpperCase() + match.substr(1);

         });

       };

             

       //Change all bookmarks to lower case

       function DumpBookmark1(bm, nLevel)

       {

              var s = "";

              for (var i = 0; i < nLevel; i++)

              if (nLevel >0)

                     {

                  s= bm.name;

                  bm.name = s.toLowerCase();

                }

              if (bm.children != null)

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

                 DumpBookmark1(bm.children,nLevel+1);

       }

       DumpBookmark1(this.bookmarkRoot, 0);

             

       //Change all bookmarks to Title Case

       function DumpBookmark2(bm, nLevel)

       {

              var s = "";

              for (var i = 0; i < nLevel; i++)

              if (nLevel >0)

                     {

                  s= bm.name;

                  bm.name = s.toTitleCase();

                }

              if (bm.children != null)

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

                 DumpBookmark2(bm.children,nLevel+1);

       }

       DumpBookmark2(this.bookmarkRoot, 0);

             

       //Change 1st level bookmarks to UPPERCASE

       var root = this.bookmarkRoot;

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

       {

              root.children.name = root.children.name.toUpperCase();

       }

My Product Information:
Acrobat Pro 8.1.6, Windows
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.032 seconds.