4 Replies Latest reply on Jan 12, 2015 3:01 AM by Test Screen Name

    get quads for word

    lindaeliseruble Level 1

      I would like to know how to get the coordinates for a word and found the following code example:

      +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

      var nPage = 75;
      var nWord = 26;


      // get quads for word
      var qQuad = this.getPageNthWordQuads(nPage,nWord);


      // convert quads to string
      var sQuad = aQuad.toString();

      console.println("Quad as sting: " + sQuad + "\n");

      // convertsQuad string to an array
      var aQuad = sQuad.split(",");
      console.println("Elements in quad array: " + aQuad.length);
      for (i = 0; i < aQuad.length; i++) console.println("element: " + i + " value: " + aQuad[i]);

      +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

      I tried to run the code in my Console, I got "undefined"

      Can you tell me what I am doing wrong?

      Thanks

      Linda

        • 1. Re: get quads for word
          try67 MVP & Adobe Community Professional

          Did you select the entire code when you ran it?

          "undefined" just means the executed code ended without errors or returning

          any values.

          Also, does your file has at least 76 pages in it?

           

          On Sun, Jan 11, 2015 at 11:01 PM, lindaeliseruble <forums_noreply@adobe.com>

          • 2. Re: Re: get quads for word
            lindaeliseruble Level 1

            Gilad,

             

            Yes, I selected the entire code when I ran it.

             

            Also, my file has 224 pages.

             

            I found the problem with the code, however.

             

            The following code should be:

            var sQuad = qQuad.toString();

            instead of:

            var sQuad = aQuad.toString();

             


            So the correct code is this:

            ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

             

            var nPage = 75;
            var nWord = 26;


            // get quads for word
            var qQuad = this.getPageNthWordQuads(nPage,nWord);


            // convert quads to string
            var sQuad = qQuad.toString();

             

            console.println("Quad as sting: " + sQuad + "\n");

            // convertsQuad string to an array
            var aQuad = sQuad.split(",");
            console.println("Elements in quad array: " + aQuad.length);


            for (i = 0; i < aQuad.length; i++);
            console.println("element: " + i + " value: " + aQuad[i]);

            ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

             

             

            When I run the code I get this:

            ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

            Quad as sting: 646.343994140625,558.6859741210938,663.0668334960938,558.6859741210938,646.343994140625,5 50.3560791015625,663.0668334960938,550.3560791015625

            Elements in quad array: 8

             

            element: 0 value: 646.343994140625
            element: 1 value: 558.6859741210938
            element: 2 value: 663.0668334960938
            element: 3 value: 558.6859741210938
            element: 4 value: 646.343994140625
            element: 5 value: 550.3560791015625
            element: 6 value: 663.0668334960938
            element: 7 value: 550.3560791015625

            true

             

            +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


            Now I would like to know why there are eight values.  Shouldn't there be only four? 

             

            For instance, when I run, this code, I only get four numbers:

            this.getField("Button1").rect;

             

             

            Like this:

            643.9056396484375,561.2030029296875,666.0845947265625,551.1866455078125

             

             

            Which of the eight numbers would coordinate with the four numbers in the result of this.getField("Button1").rect; ?

             

             

             

            Thanks

             

             

             

            Linda

             

             

             

             

            • 3. Re: Re: get quads for word
              try67 MVP & Adobe Community Professional

              The quads are not the same as a rect. They are defined as "an array of 8 x n numbers specifying the coordinates of n quadrilaterals in default user space", while a rect is located in the rotated user space. It's possible to convert one to the other, but it's complex.

              • 4. Re: get quads for word
                Test Screen Name Most Valuable Participant

                Documentation for this method is not so useful as the documentation for JavaScript > JavaScript for Acrobat API Reference > JavaScript API > Annotation > Annotation properties > quads

                 

                Quadrilaterals may not be grid aligned (45 degree rotated text) and may not be rectangular (faked italics)