3 Replies Latest reply on Jul 2, 2014 10:29 AM by ChrisMcCauley

    Find and add links to words to a particular page

    Muthuraj Durairaj Level 1

      Hi All,

       

      I have a large document and my requirement is to find the a set of words and add gotopage link to a particular page (index page). I recently got a action file from Acrobat users group (http://acrobatusers.com/content/find-highlight-words-and-phrases) which find and highlight a set of words using Acrobat action.

       

      This action consists of "search and Remove Text" action which will search and redact the selected text and a javascript to add yellow color highlight.

       

      Is this possible to modify the javascript to add a gotopage action (using link properties) with no stroke and highlight color? I have attached the .sequ file and below is the javascript available in that file.

       

      Thanks a lot for all your help.

       

       

      var colHilite = color.yellow;
      var oDoc = event.target;
      
      
      var aAnnts = oDoc.getAnnots({sortBy:"Author"});
      for(var i=0;i<aAnnts.length;i++)
      {
         if(aAnnts[i].type == "Redact")
         {
            aAnnts[i].type = "Highlight";
            aAnnts[i].strokeColor = colHilite;
         }
      }
      
      

       

       

      Regards,

      Muthuraj. D

        • 1. Re: Find and add links to words to a particular page
          maxwyss Level 4

          I am not quite sure if I understand correctly what should be accomplished.

           

          If it is essentially to find a word, and then create a link to a separate page, it is possible.

           

          Finding the word using the Redaction tool is pretty straightforward, as we see. This gives, as we can see in the script an annotation of the "Redact" type. Now, we can read out the coordinates of the annot highlight, and directly create the link based on these coordinates. Finally we destroy the annotation, and we have what we need. We can set the border color of the link to transparent, and then there would be no visual hint for the link.

           

          However, if we need the highlight, we have to keep the annotation, and change it, as shown in the script, as Highlight annotation. The problem is now that because of bugs in Acrobat, annotations seem not to honor properly the readonly property. So, if we can guarrantee that the link will always be on top of the annotation, it will protect it, and the active surface comes from the link.

           

          Hope this can help.

           

          Max Wyss.

          1 person found this helpful
          • 2. Re: Find and add links to words to a particular page
            Muthuraj Durairaj Level 1

            Hi Max Wyss,

             

            Thanks for your quick reply, it is really helpful.

             

            As you said,

            Finding the word using the Redaction tool is pretty straightforward, as we see. This gives, as we can see in the script an annotation of the "Redact" type. Now, we can read out the coordinates of the annot highlight, and directly create the link based on these coordinates. Finally we destroy the annotation, and we have what we need. We can set the border color of the link to transparent, and then there would be no visual hint for the link.

             

            This is what I exactly need. Can we acheive the above said by modifying the accompanying javascript added in the actions? I am beginner in Acrobat Javascript and could you please help me on this by writing this code for me. Thanks a ton.

             

            I have found this following code in Acrobat API reference. It is searching for a single word and works perfectly. Can we improve this code to find for a list of words?

             

             

            for (var p = 0; p < this.numPages; p++)
            {
            var numWords = this.getPageNumWords(p);
            for (var i=0; i<numWords; i++)
            {
            var ckWord = this.getPageNthWord(p, i, true);
            if ( ckWord == "Acrobat")
            {
            var q = this.getPageNthWordQuads(p, i);
            // Convert quads in default user space to rotated
            // User space used by Links.
            m = (new Matrix2D).fromRotated(this,p);
            mInv = m.invert()
            r = mInv.transform(q)
            r=r.toString()
            r = r.split(",");
            l = addLink(p, [r[4], r[5], r[2], r[3]]);
            l.borderColor = color.red
            l.borderWidth = 0
            //l.setAction("this.getURL('http://www.adobe.com/');");
            l.setAction("this.pageNum = 2");
            }
            }
            }
            
            

             

            Please help.

             

            Regards,

            Muthuraj. D

            • 3. Re: Find and add links to words to a particular page
              ChrisMcCauley

              I use a similar script. To add additional words, try replacing the numbers in ch = 2, ch = 3, etc. with the term you are searching for, and change the numbers in ChapPage = 15, ChapPage = 63, etc. with the destination page of the link for that word.

               

              ch = ckWord;

              if (ch == 1) { ChapPage = 15; }
              else if (ch == 2) { ChapPage = 63; }
              else if (ch == 3) { ChapPage = 211; }
              else if (ch == 4) { ChapPage = 335; }
              else if (ch == 5) { ChapPage = 435; }
              else if (ch == 6) { ChapPage = 491; }
              else if (ch == 7) { ChapPage = 563; }
              else if (ch == 8) { ChapPage = 625; }
              else if (ch == 9) { ChapPage = 735; }
              else if (ch == 10) { ChapPage = 867; }
              else if (ch == 11) { ChapPage = 903; }
              else if (ch == 12) { ChapPage = 969; }
              else if (ch == 13) { ChapPage = 1389; }
              else if (ch == 14) { ChapPage = 1433; }
              else if (ch == 15) { ChapPage = 1459; }
              else if (ch == "Index") { ChapPage = 1503; }

              pg = ChapPage;

              ...

              ...
              l.setAction("this.pageNum="+pg);

               

              Of course, if you have a lot of words to link, you will have a long list of conditions. But it should work.