7 Replies Latest reply on Dec 7, 2010 6:45 PM by RainbowChunChunChang

    Alter existing Javascript to move location of items on pages

    miss-charlotte Level 1

      Hi there,

       

      I have a script to 'Add Navigation Buttons To All Pages' below. (I am working with a 300 page PDF.)

       

      Question:

      How do I alter this so it places the buttons on the top RIGHT hand side of every page - as opposed to the LEFT hand side of the page as it does now?

       

      Here is the script:

      -----------------------------

       

      // Add navigation buttons to the page

      // This script puts 3 buttons on top of every page (except the first one that has one button)

      // First button "<" : takes to the previous page

      // Second button: "1" : takes to the first page of the document

      // Third button: ">" : takes to the next page in the document (does not exists on the last page)

       

      var inch = 72;

       

      try

      {

       

          nLastPage = this.numPages - 1;

       

          for (var p = 0; p < this.numPages; p++)

          {

              var x = 0.5;

       

              if (p > 0)

              {

                  AddButton(p,x,0.5,0.25,0.25,"PrevPage","<","Previous Page","this.pageNum--;"); // left arrow, previous page

                  x += 0.3;

              }

       

              if (p != 0)

              {

                  AddButton(p,x,0.5,0.25,0.25,"StartPage","1","Go To First Page","this.pageNum=0;"); // "1", takes to the first page

                  x += 0.3;

              }

       

              if (p < nLastPage)

              {

                  AddButton(p,x,0.5,0.25,0.25,"NextPage",">","Next Page","this.pageNum++;"); // right arrow, next page

                  x += 0.3;

              }

       

              AddButton(p,x,0.5,0.25,0.25,"Back","<<","Go Back","app.execMenuItem(\"GoBack\");"); // right arrow, next page

              x += 0.3;

       

          }

       

      }

       

       

      catch (e)

      {

      app.alert(e);

      }

       

      // AddButton function creates a button with given parameters and action

       

      function AddButton(nPageNum, x, y, width, height, strText, strCaption, strToolTip, strAction)

      {

          var aRect = this.getPageBox( { nPage: nPageNum} );

          aRect[0] += x * inch;

          aRect[1] -= y * inch;

          aRect[2] = aRect[0] + width * inch;

          aRect[3] = aRect[1] - height * inch;

       

          var f = this.addField(strText,"button", nPageNum, aRect);

          f.setAction("MouseUp",strAction);

          f.userName = strToolTip;

          f.delay = true;

          f.borderStyle = border.s;

          f.highlight = "push";

          f.textSize = 0; // autosized

          f.textColor = color.blue;

          f.strokeColor = color.blue;

          f.fillColor = color.white;

          // you can specify a different font here, otherwise it uses a default one

          //f.textFont = font.ZapfD;

          f.buttonSetCaption(strCaption);

          f.delay = false;

      }

        • 1. Re: Alter existing Javascript to move location of items on pages
          gkaiseril MVP & Adobe Community Professional

          It looks like the assignment of the value to variable 'x' determines the distance of the first button from the left margin in inches. 'y' is the distance in inches from the top of the page. Do not change the incrementing of 'x' for each additional button being added.

          • 2. Re: Alter existing Javascript to move location of items on pages
            miss-charlotte Level 1

            Hi G,

             

            I'm a newbie at this so thanks for your help.

             

            Where would i change that in the script?  I see references to x and y different areas but don't know what/where to change.

             

            This this is an easy answer?

             

            Is it possible to change my script for me?

             

            Thanks!

            • 3. Re: Alter existing Javascript to move location of items on pages
              miss-charlotte Level 1

              I figured it out!!! Thanks for your help G!

              • 4. Re: Alter existing Javascript to move location of items on pages
                RainbowChunChunChang

                Can you post the corrected script ?

                 

                what was the flaw in it ?

                 

                works nicely so I wonder .............

                 

                 

                • 5. Re: Alter existing Javascript to move location of items on pages
                  miss-charlotte Level 1

                  Hi there, I tweaked the x y so it moved over to the right. I don't have exact information at this moment.

                  But it all turned out to be unnecessary in the end, as I updated my software and got the "duplicate" on all pages feature back.

                  My objective was to duplicate 4 navigational page links in the sample place on each page over 300 pages.

                  Thanks

                  • 6. Re: Alter existing Javascript to move location of items on pages
                    miss-charlotte Level 1

                    Hi Rainbow - I found it... so it moved things over to right....

                    ------------

                    // Add navigation buttons to the page

                    // This script puts 3 buttons on top of every page (except the first one that has one button)

                    // First button "<" : takes to the previous page

                    // Second button: "1" : takes to the first page of the document

                    // Third button: ">" : takes to the next page in the document (does not exists on the last page)

                     

                    var inch = 72;

                     

                    try

                    {

                     

                        nLastPage = this.numPages - 1;

                     

                        for (var p = 0; p < this.numPages; p++)

                        {

                            var x = 0.5;

                     

                            if (p > 0)

                            {

                                AddButton(p,x,0.5,0.25,0.25,"PrevPage","<","Previous Page","this.pageNum--;"); // left arrow, previous page

                                x += 0.3;

                            }

                       

                            if (p != 0)

                            {

                                AddButton(p,x,0.5,0.25,0.25,"StartPage","1","Go To First Page","this.pageNum=0;"); // "1", takes to the first page

                                x += 0.3;

                            }

                       

                            if (p < nLastPage)

                            {

                                AddButton(p,x,0.5,0.25,0.25,"NextPage",">","Next Page","this.pageNum++;"); // right arrow, next page

                                x += 0.3;

                            }

                     

                            AddButton(p,x,0.5,0.25,0.25,"Back","<<","Go Back","app.execMenuItem(\"GoBack\");"); // right arrow, next page

                            x += 0.3;

                           

                        }

                     

                    }

                     

                     

                    catch (e)

                    {

                    app.alert(e);

                    }

                     

                    // AddButton function creates a button with given parameters and action

                     

                    function AddButton(nPageNum, x, y, width, height, strText, strCaption, strToolTip, strAction)

                    {

                        var aRect = this.getPageBox( { nPage: nPageNum} );

                        aRect[0] = aRect[2] - x * inch - width;

                        aRect[1] -= y * inch;

                        aRect[2] = aRect[0] + width * inch;

                        aRect[3] = aRect[1] - height * inch;

                     

                        var f = this.addField(strText,"button", nPageNum, aRect);

                        f.setAction("MouseUp",strAction);

                        f.userName = strToolTip;

                        f.delay = true;

                        f.borderStyle = border.s;

                        f.highlight = "push";

                        f.textSize = 0; // autosized

                        f.textColor = color.blue;

                        f.strokeColor = color.blue;

                        f.fillColor = color.white;

                        // you can specify a different font here, otherwise it uses a default one

                        //f.textFont = font.ZapfD;

                        f.buttonSetCaption(strCaption);

                        f.delay = false;

                    }

                    • 7. Re: Alter existing Javascript to move location of items on pages
                      RainbowChunChunChang Level 1

                      It appears that there is a logic redundancy in your code.

                       

                              var x = 0.5;
                              if (p > 0){ // left arrow, previous page ... NOTE: AddButton() calls addField()
                                  AddButton(p,x,0.5,0.25,0.25,"PrevPage","<","Previous Page","this.pageNum--;");
                                  x += 0.3;
                              }
                              if (p != 0){ // "1", takes to the first page
                                  AddButton(p,x,0.5,0.25,0.25,"StartPage","1","Go To First Page","this.pageNum=0;");
                                  x += 0.3;
                              }

                       

                      could be reduced to

                       

                              var x = 0.5;
                              if (p > 0){ // left arrow, previous page ... NOTE: AddButton() calls addField()
                                  AddButton(p,x,0.5,0.25,0.25,"PrevPage","<","Previous Page","this.pageNum--;");
                                  x += 0.3;
                      //       }
                      //       if (p != 0){ // "1", takes to the first page
                                  AddButton(p,x,0.5,0.25,0.25,"StartPage","1","Go To First Page","this.pageNum=0;");
                                  x += 0.3;
                              }

                       

                      as the two conditions are equivalent.

                       

                      If you find my reply helpful dont forget to click for helpful reply and give a credit.

                       

                      Also, I sent you a PM.

                       

                      Rainbow