3 Replies Latest reply on Jun 22, 2010 11:37 PM by DV22

    Convert search info to bookmark

    jay fresno Level 1

      Does anyone know of a script that will take information from a search and create bookmarks from that search information? For example, if there is a word, such as "Consultant" that appears periodically throughout a PDF file, and a full search is performed for that word, Acrobat creates a list in the Search panel. If there is a script that would take the search results and create bookmarks for those results, it would be very useful for me.

        • 1. Re: Convert search info to bookmark
          DV22

          While I don't have the bookmark part offhand, I do have a search function done that you could adjust for bookmarking.

          I use this as a batch sequence, so if used elsewhere you may have permission trouble depending on how far you take it.

          Hope this helps.

           

           

          /* Search Phrase */

          // start searching for key words
          searchIt("Consultant");
          app.execMenuItem("SaveAs");

           

          // does 3 loops:
          // cycle through all pages (var i)
          // cycle through all words (var j)
          // combine words to match number of words in search phrase (tmpLen, ckWord)
          // if matches, push the page number to our global array list and exit function
          // meaning it will only return the first instance of the phrase
          function searchIt(srchStr) {
              var ckWord, numWords;

               if (srchStr.indexOf(" ") != -1 ) {
                   var tmpArr = srchStr.split(" ");
                   var tmpLen = tmpArr.length;

               } else {

                    var tmpLen = 1;

               }
              for (var i = 0; i < this.numPages; i++) {
                  numWords = this.getPageNumWords(i);
                  for (var j = 0; j < numWords; j++) {
                      ckWord = this.getPageNthWord(i,j);
                      for (var t=1; t<tmpLen;t++) {
                          if (j+tmpLen < numWords) {
                              ckWord += " "+this.getPageNthWord(i,j+t)
                          }
                      }
                      if (ckWord == srchStr){ // means our search word is on this page!
                          // add bookmark stuff here

                          // srchStr is the name

                          // i is the current page

                      }
                  }
              }
          }

          • 2. Re: Convert search info to bookmark
            jay fresno Level 1

            DV22,

             

            I greatly appreciate your script. However, I must be doing something wrong because after making it into a batch process, and running the batch process, nothing happened. I also tried using the script in a button with no results. I don't know how to script, so there may be something really simple that I'm just not doing right. Do you have any suggestions as to why I'm not getting any results?

            • 3. Re: Convert search info to bookmark
              DV22 Level 1

              Sorry for the confusion, late shift and all...

               

              The script as it stands is only the search part, I'm not overly familiar with how Bookmarks work but I was guessing it'd need the page number so I thought I'd throw the "search and get page number" part up.

               

              If I remember right, I'd look into the Javascript API under bookmark and insertChild or createChild, I dont have it with me at the moment but hopefully that will lead you (or let your refine your Googling) closer to your final script.