2 Replies Latest reply on Sep 27, 2011 3:21 PM by JoFrmOZ

    Extract Pages by Sub Bookmarks for Number of Pages

    JoFrmOZ Level 1

      I have a script which will extract the document at the bookmark page.

       

      I need to further modify the script to extract the number of pages from the bookmark for nEnd.

       

      nEnd will be the LAST sub boomark from nStart which is the first bookmark.

       

      Script as follows:

       

      if (this.bookmarkRoot.children!=null)

      {

      for (var i=0; i < this.bookmarkRoot.children.length; i++)
      for (var j=this.bookmarkRoot.children[i].children.length-1; j >= 0; j--)
      {

      var bm = this.bookmarkRoot.children[i].execute();
      var bms = this.bookmarkRoot.children[i].children[j].execute(); \\\ this part is not working for nEnd
      var bmname = this.bookmarkRoot.children[i].name;

      this.extractPages({nStart:bm+ this.pageNum++, nEnd:bms+ this.pageNum++,  cPath: "/C/Temp/"+ bmname +".pdf"});

      }

      }

       

      Any assistance will be most appreciated, thank you.

        • 1. Re: Extract Pages by Sub Bookmarks for Number of Pages
          Thom Parker Adobe Community Professional

          Ok, you need to collect the page numbers the  bookmarks navigate to separately, If you're looking at the last sub-bookmark then you also don't need the inner loop

           

           

          How about this.

           

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

          {

               this.bookmarkRoot.children[i].execute();

               var nStart = this.pageNum;

               var nEnd = nStart;

               if( this.bookmarkRoot.children[i].children)

               {// Only look for the end if sub-bookmarks exist

                  var nLastSub = this.bookmarkRoot.children[i].children.length-1;

                  this.bookmarkRoot.children[i].children[nLastSub].execute();

                  nEnd = this.pageNum;

              }

              this.extractPages({nStart:nStart, nEnd:nEnd, ....});

          }

           

          Thom Parker
          The source for PDF Scripting Info
          pdfscripting.com

           

          The Acrobat JavaScript Reference, Use it Early and Often
          http://www.adobe.com/devnet/acrobat/javascript.html

           

          Then most important JavaScript Development tool in Acrobat
          The Console Window (Video tutorial)
          The Console Window(article)

          • 2. Re: Extract Pages by Sub Bookmarks for Number of Pages
            JoFrmOZ Level 1

            Thank you Thom.

             

            The script works perfectly and splits the file from the top bookmark as the starting page to the last sub bookmark for the end page.

             

            Many thanks again!

             

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

            {

                 this.bookmarkRoot.children[i].execute();

                 var nStart = this.pageNum;

                 var nEnd = nStart;
             
                  var bmname = this.bookmarkRoot.children[i].name;

                 if( this.bookmarkRoot.children[i].children)

                 {// Only look for the end if sub-bookmarks exist

                    var nLastSub = this.bookmarkRoot.children[i].children.length-1;

                    this.bookmarkRoot.children[i].children[nLastSub].execute();

                    nEnd = this.pageNum;

                }

                this.extractPages({nStart:nStart, nEnd:nEnd, cPath: "/C/Temp/"+ bmname +".pdf"});

            }