Skip to main content
吉加司松46451774
Participant
September 28, 2024
Question

Even though the string is recognised as text, it cannot be searched using the searchForText method.

  • September 28, 2024
  • 1 reply
  • 534 views

Despite the text strings being recognized as text, the searchForText method is unable to locate them. The error message "TypeError: searchResults is undefined" is displayed. I would be grateful if you could provide a corrected code snippet.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
September 28, 2024

I'm not familiar with this method. Can you post your full code, please?

吉加司松46451774
Participant
September 29, 2024

Thanks for replying.
I will send you the code I have created.


var targetTexts = ["LD", "MBR", "BR", "BR1", "BR2"];
var grayColor = color.rgb(192, 192, 192); 


for (var pageNum = 0; pageNum < this.numPages; pageNum++) {
var page = this.getPage(pageNum);


page.searchForText({
text: targetTexts.join("|"), 
caseSensitive: false,
wholeWordsOnly: true, 
}).forEach(function(searchResult) {

searchResult.textColor = grayColor;
});
}

try67
Community Expert
Community Expert
September 29, 2024

Don't know where you got this code from (ChatGPT?), but it's not valid code for Acrobat JS.

There's no getPage method, nor a searchForText method.