Bug when searching words with search.query() from JavaScript
I found a fatal language-dependent bug in advanced search.
Using "Advanced Find" to find words in a PDF, actions that could be done manually did not work in Javascript.
Write a sample script below.
Create a file in UTF-8 .js file format and place the file in "C:\Program Files\Adobe\Acrobat DC\Acrobat\Javascripts".
Then restart Acrobat and you should see a new menu at the top within the File menu.
This script can be run from there.
When the script runs, the text in the open PDF is examined to see if it contains the searched characters.
However, we have confirmed that Unicode characters other than English such as Japanese and Chinese cannot be searched normally under the following conditions.
If you set Acrobat's menu language to Japanese, basic English and Japanese characters will get search support, but Chinese characters will not be recognized and will be garbled.
If Acrobat menu language is set to English, all non-English characters are garbled.
It seems to rely on menu language settings, but these are not manifested when doing a manual search.
So the internal behavior of running the script is not adjusted, causing problems.
My environment uses both Win10 and Win11.
Acrobat Pro is the latest version.
Originally, the text to be searched is entered in the text box, but if the text is garbled, the target character is replaced with a period.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-= JavaScript =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//add new menu button
app.addSubMenu(
{
cName: "Test Script",
cParent: "Edit", nPos: 0
}
);
//add sub menu
app.addMenuItem(
{
cName: "Test Search",
cParent: "Test Script",
nPos:0,
cEnable:!1,
cExec: "TestSearchFunc()"
}
);
TestSearchFunc = app.trustedFunction(
function (){
//search options
search.wordMatching = "MatchAnyWord";
search.matchWholeWord = false;
search.matchCase = false;
search.proximityRange = false;
search.stem = false;
search.bookmarks = false;
search.markup = false;
search.attachments = false;
var str = "Search Text. JP Text > 日本語 China Text > 国际级";
search.query(str, "ActiveDoc");
}
);
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
I can't predict whether there is any merit in restricting searchable characters by language. If I had to say it, would it be racism or a protest against the government? lol