1 Reply Latest reply on Mar 10, 2012 4:47 PM by gkaiseril

    Code to Automatically Figure and Report Page #? [easy]

    stealthrs Level 1

      Hi, I've made a 100 page PDF that will have changes/updates made every now and then to the order...  Not all 100 pages are needed at all times, so I've made a checkbox that reports to another text field and keeps of what pages are needed when the box is checked yes...

       

      The working code is below, but is there a way I can code it so it knows what page number it's on automatically?.... Without me having to use manual code as seen below in the Red Text?  I re-organize the pages from time to them, which means I have to manually go back through and update the code.  Can I fix this?

       

      Thanks!  See the code below!

       

      // script start

       

      //get the button

      var btn = this.getField("13_travel");

      //app.alert("value = "+btn.value);

       

       

      // this variable would change for each check box to the pages you want printed.

      var pagesToPrint = "92";

       

       

      //check value of checkbox

      if(btn.value=="Yes") {

          var action = "add";

      }

      else

      {

          var action = "";

      }

       

      updatePagesToPrint(pagesToPrint, action);

       

       

       

      function updatePagesToPrint(pagesToPrint, action) {

          //app.alert(pagesToPrint + " :: " + action);

       

          // get the text field

          var printField = this.getField("pagesToPrint");

       

          if(action=="add")

          {

              // check if the field is empty

              if ( printField.value == "" || printField.value == " ")

              {   

                   printField.value = pagesToPrint;

              }

              else

              {

                   // as printField has a value, add the new pages to the end of the value

                   printField.value = printField.value + ", " + pagesToPrint;

              }

          }

          else

          {

              printField.value = printField.value.replace(pagesToPrint+", ", "");

              printField.value = printField.value.replace(pagesToPrint, "");

              printField.value = printField.value.replace(/^,|^, |, $|,$/, "");

          }

       

      }

       

       

      // script end

        • 1. Re: Code to Automatically Figure and Report Page #? [easy]
          gkaiseril MVP & Adobe Community Professional

          When on a page, the doc object "pageNum" reports the page number of that page. So for a field on any page:

           

          var pagesToPrint = this.pageNum;

           

          will report the number of the page.

           

          If you are dealing with numbers, it is better not to put them in quotation marks unless you want a text string of numbers. 

           

          For the total number of pages in a document you can use the "this.numPages" property.