.toUpperCase() method working only once with getPageNthWord
Hello,
I'm beginner to JavaScript and Acrobat JS api. I'm trying to write a script which makes annotations on phrases instead of single words, and I wanted it to be case insensitive. Therefore logically, I thought of using .toUpperCase() method on both this.getPageNthWord(p, w) and the words searched. To simplify it's use for multiple sentences, every phrases entered are pushed in an array and the annotation function is called for every items in this array.
But the problem is that when I launch the script, the annotation is made only for the first phrase in the array and I get a "TypeError: this.getPageNthWord(p, w) has no properties" in the console.
Here is a basic case which reproduces the exact same problem.
In this example this is only an array of words which is searched for annotations, but as in my case, only the first word is highlighted and we get the same "TypeError: this.getPageNthWord(p, w) has no properties"
function DoHighlight(word)
{
for (var p = 0; p < this.numPages; p++)
{
var cnt = this.getPageNumWords(p);
for (var w = 0; w < cnt; w++)
{
if (this.getPageNthWord(p, w).toUpperCase() == word.toUpperCase())
{
this.addAnnot({
page: p,
type: "Highlight",
strokeColor: color.red,
quads: this.getPageNthWordQuads(p, w),
});
}
}
}
}
var words = ["word1","word2"];
var t = words.forEach(function Highlight(word){ DoHighlight(word) });
I know that there is already actions for phrase & word annotation here https://acrobatusers.com/actions-exchange , but as I'm a beginner I would really like to understand why it only works on the first element, and how I can fix it. And also I would like to create custom actions with this one later.
Any help / explanation would be very appreciated!
