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

Trying to search for words and add annotations to each word

StevenD
Registered: Oct 6 2006
Posts: 368

I'm trying to search for the word Chapter on a Contents page and add the word to the note contents. The script below works fine. I would like to get the next word after "Chapter" so I end up with "Chapter 1", "Chapter 2" and so forth. There has got to be a way to get the next word and add it to the "Chapter". I just can't get it to work. Any suggestions or tips would be most helpful.

/*
var numWords = this.getPageNumWords(2);
for (var i = 0; i < numWords; i++)
{
var myWord = this.getPageNthWord(2, i);
if (myWord == "Chapter")
{
this.addAnnot({
page: 2,
type: "Underline",
quads: this.getPageNthWordQuads(2, i),
contents: myWord
});
}
}
*/

I thought I could get the word next to the word "Chapter" by using the following line of code but it doesn't seem to work and I'm not sure what I am doing wrong.

//this.getPageNthWord(2, (i + 1);

StevenD

My Product Information:
Acrobat Pro Extended 9.3.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The line of code you posted should work. What does it return?

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

StevenD
Registered: Oct 6 2006
Posts: 368
Nothing. I did notice that I believe I'm missing a closing ")".

StevenD

StevenD
Registered: Oct 6 2006
Posts: 368
After my original post I kept working at it and I came up with a working solution although I thought this could be done without haveing to add the extra lines of code.

var numWords = this.getPageNumWords(2);
for (var i = 0; i < numWords; i++)
{
var myWord = this.getPageNthWord(2, i, true);

//I added these two lines of code
var myNum = i + 1;
var myChapNum = this.getPageNthWord(2, myNum);

if (myWord == "Chapter")
{
this.addAnnot({
page: 2,
type: "Underline",
quads: this.getPageNthWordQuads(2, i),

//I modified this line by concatenating Chapter and the number.
contents: myWord + " " + myChapNum

});
}
}

Another interesting thing was when I tried to turn off the remove punctuation and white space by changing that parameter to false the script wouldn't work. That is why I added the '+ " " +' to give me a space between the Chapter and number ei. "Chapter 1" instead of "Chapter1" for the text of the annotation note.

StevenD