2 Replies Latest reply on Nov 4, 2013 1:29 PM by Jo_2013

    Text Field for Second (Nth Word) on Page

    Jo_2013

      The script as follows adds text fields on a page based on finding the word DATE.

       

      This script needs to be modified to add the text field for the second occurance of the word DATE only on the page and NOT the first occurance of the word.

       

      Currently the script add a text field for all occcurances of the word DATE.

       

      Any assistance will be greatly appreciated.

       

      Thank you.

       

       

      /*Add date text field on manual transmittal*/

      var numpages = this.numPages;

      for (var k=0; k < numpages; k++)

      /*1st co-ord = Horizontal, 2nd co-ord = vertical, 3rd co-ord = width, 4th co-ord = height*/

      {

      {

      var numWords = this.getPageNumWords(k);

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

      {

      var ckWord = this.getPageNthWord(k, i, true);

      if ( ckWord === "DATE")

      {

      var q = this.getPageNthWordQuads(k, i);

      // Convert quads in default user space to rotated

      // User space used by Links.

      m = (new Matrix2D).fromRotated(this,0);

      mInv = m.invert()

      r = mInv.transform(q)

      r=r.toString()

      r = r.split(",");

      var f = this.addField("Date", "text", k,

      [r[0]*1.10, r[1]-10, r[2]*1.3, r[5]-15]);

      }

      }

      }

      }

        • 1. Re: Text Field for Second (Nth Word) on Page
          George_Johnson MVP & Adobe Community Professional

          Try something like this:

           

          var numpages = this.numPages;


          for (var k = 0; k < numpages; k++) {

           

              var nDateCount = 0;  // Initialize counter

              var numWords = this.getPageNumWords(k);


              for (var i = 0; i < numWords; i++) {


                  var ckWord = this.getPageNthWord(k, i, true);


                  if (ckWord === "DATE") {


                      nDateCount += 1;  // Increment counter


                      if (nDateCount == 2) {

                          var q = this.getPageNthWordQuads(k, i);

                          var m = (new Matrix2D).fromRotated(this,0);

                          var mInv = m.invert();

                          var r = mInv.transform(q);

                          r = r.toString();

                          r = r.split(",");

                          var f = this.addField("Date", "text", k, [r[0]*1.10, r[1]-10, r[2]*1.3, r[5]-15]);

                          break;  // No need to keep searching current page

                      }

                  }

              }

          }

          • 2. Re: Text Field for Second (Nth Word) on Page
            Jo_2013 Level 1

            Thank you very much for your help George

             

            The modification to the script with the counter now adds the text field for the second occurance of the word DATE.

             

            Much appreciated!