• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

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.

TOPICS
How to , JavaScript , PDF

Views

83

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2024 Sep 28, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 28, 2024 Sep 28, 2024

Copy link to clipboard

Copied

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;
});
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2024 Sep 29, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 29, 2024 Sep 29, 2024

Copy link to clipboard

Copied

LATEST

When you use the script in Acrobat you will get this error:

TypeError: color.rgb is not a function

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines