These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Document Search

JNorris
Registered: Sep 7 2011
Posts: 31
Answered

I've read some of the JS API for this section but still couldn't achieve what I wanted.
 
I am trying to search the file for a string of words. Then based on a match, create a bookmark. I can do this, but not when I want to make multiple queries under the same Action. Is there a workaround?
 
Here's my code for a single query which works fine:
 
var thesearch = search.query("blah blah blah", "ActiveDoc");
 
if (thesearch!=null) {
 
this.bookmarkRoot.createChild({cName:"Bookmark Name", cExpr:"this.pageNum=" + thesearch.pageNum, nIndex: this.numPages-1})
}

My Product Information:
Acrobat Pro 10.0, Windows
JNorris
Registered: Sep 7 2011
Posts: 31
Additional info: What I want is for every instance found to create a bookmark at that page.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to read the documentation more carefully. search.query() does not return any meaningful value. It merely opens the built-in Advanced Search window and executes the search you specify.

If you want to find out whether a document contains a certain phrase you need to use getPageNthWord().

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

JNorris
Registered: Sep 7 2011
Posts: 31
Think I got it, but let me know if there might be any complications:



var numwords;

for (var i=0; i < this.numPages; i++)
{
numwords = this.getPageNumWords(i);
for (var j=0; j< numwords; j++)
{
if (this.getPageNthWord(i,j) =="word1"){
if (this.getPageNthWord(i,j+1) =="word2"){
if (this.getPageNthWord(i,j+2) =="word3"){
if (this.getPageNthWord(i,j+3) =="word4"){
this.bookmarkRoot.createChild({cName:"Bookmark Name", cExpr:"this.pageNum=" + i, nIndex: this.numPages-1})
j=numwords;
}}}}
}
}


Is there a better way to match subsequent words on a page? Also, this process takes a long time. So more importantly, is there a better way to cut down the script so that the wait time is more manageable?

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
First of all, you should change the final value of numwords to the number of words in the page minus the number of words you want to look for (4 in this case), because getPageNthWord will throw an exception if you're trying to access a word index which is higher than the total number of words on that page.

There's no real way to improve this, as far as I can see, except by adding a label to the pages loop (for example, "pagesLoop") and calling "continue pagesLoop" in case a match was made, which is kind of what you did by using j=numwords.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com