2 Replies Latest reply on Oct 17, 2014 5:59 AM by subieguy2

    Create button to size of text

    subieguy2 Level 3

      I have a JavaScript function in Acrobat 8 Pro that will create a button on top of numbers. The document looks like this....


      Then I run the following code....

          var page = this.pageNum;
          // var numWords = this.getPageNumWords(page);
          var numWords = 1000;
          for (var i = 0; i < numWords; i++) {
              var ckWord = this.getPageNthWord(page, i);
              var stringInt = parseInt(ckWord);
              for (var counter = 0; counter < numWords; counter++) {
                  if (stringInt == counter) {
                      var q = this.getPageNthWordQuads(page, i);
                      m = (new Matrix2D).fromRotated(this, page);
                      mInv = m.invert()
                      r = mInv.transform(q)
                      r = r.toString()
                      r = r.split(",");
                      var l = this.addField(('000' + ckWord).substr(-3) + "_callout", "button", page, [r[4], r[5], r[2], r[3]]);
                      l.setAction("MouseUp", "this.callout" + ('000' + ckWord).substr(-3) + "();");
                      l.userName = "Machine Location";


      The code places buttons on top of the numbers like this.....


      Is there a way to make the button the size of the text it is associated with? Right now we are manually sizing the buttons to fit on top of the text and it would be awesome if the code would make them the size it needs to be. End results look like this...


      Anyone know of a way to accomplish this with JavaScript or is it not possible?

      Thanks in advance for any help/suggestions!

        • 1. Re: Create button to size of text
          try67 MVP & Adobe Community Professional

          Since the length (and height) of the associated text varies from item to item this will quite tricky to implement.

          You will need to come up with some kind of definition which text should be included, and then collect the quads of that text and calculate the total size of the button. Not a simple task by any means.

          • 2. Re: Create button to size of text
            subieguy2 Level 3

            Ok so that is WAY beyond my abilities of programming...lol.


            I appreciate the direction on how to approach the task but until I gain better programming skills I will just continue to do them manually.


            Thanks for the input!