试图在JavaScript中用红色突出显示一个单词



我正在创建一个adobe.pdf文档,用于创建从一个页面到另一个页面的链接。在下面的JavaScript代码中;120〃;(字=="120"(。我想发生的是。。。当最终用户点击他们的初始链接并被带到该文本出现的页面时;红色";因此,图纸上的标注很容易在许多其他标注编号中找到。我不想把文本改成红色……我想突出显示它,但我不知道该怎么做。

如果我在pdf页面中有多个位置与我要查找的单词相同,则会插入if (nWait == "0")语句。

这是我一直在使用的代码,它被插入到我的adobepdf中,并带有他们的Run a JavaScript Action。我完全迷路了,有人能帮我吗?

nWait = 0;
nWords = getPageNumWords(85);
for (var loop = 0; loop < [nWords - 1]; loop++) {
word = getPageNthWord(85, loop);
if (word == "1") {
if (nWait == "0") {
this.selectPageNthWord(85, loop);
break;
}
nWait = nWait + 1;
}
}

我无法在Acrobat中运行此程序,但这应该会让您更接近目标。如果我理解你想要实现的目标,你只需要选择一个词。您的nWait变量不是必需的,只需在找到您要查找的内容后使用break即可脱离循环。


// Get the number of words on the page
var nWords = getPageNumWords(85);
// Loop over all of them. Your end-condition of the loop should just be `nWords` in this case. If the number of words is 5, your loop is going to run from 0 to 4, which is 5 times (which is what you want).
for (var loop = 0; loop < nWords; loop++) {
// Get the word from Acrobat
var word = getPageNthWord(85, loop);
// If this word is what we're looking for...
if (word === "1") {
// Select it on the page, and then break the loop as we're done
this.selectPageNthWord(85, loop);
break;
}
}

最新更新