In PDF XChange Editor, can I run advanced searches, changes search settings and annotate results from the JavaScript Console? Thanks,
Dustin
Running searches from the JavaScript Console
Moderators: TrackerSupp-Daniel, Tracker Support, Sean - Tracker, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Tracker Supp-Stefan
Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
-
- User
- Posts: 18
- Joined: Wed Aug 02, 2023 4:19 pm
- Vasyl-Tracker Dev Team
- Site Admin
- Posts: 2313
- Joined: Thu Jun 30, 2005 4:11 pm
- Location: Canada
Re: Running searches from the JavaScript Console
Hi Dustin.
There is a standard way - look for search object in Adobe's JS Reference. Then in JS console you are able to use for example:
search.matchCase = true;
search.query("document");
and then, when the search is finished, you may annotate results on pages by:
app.execMenuItem("cmd.addAnnotsBySearchResult.highlight");
The one problem will be there. The simple code like
search.matchCase = true;
search.query("document");
app.execMenuItem("cmd.addAnnotsBySearchResult.highlight");
- will not annotate results because search.query is asynchronous, so it will not wait for the search process to complete. It just starts the background search-task and immediately goes to the following command in the console. It means the execMenuItem will be called too early, before the results appear. It's the reason why I said that you need to wait with that execMenuItem until the search is complete, unfortunately.
HTH.
There is a standard way - look for search object in Adobe's JS Reference. Then in JS console you are able to use for example:
search.matchCase = true;
search.query("document");
and then, when the search is finished, you may annotate results on pages by:
app.execMenuItem("cmd.addAnnotsBySearchResult.highlight");
The one problem will be there. The simple code like
search.matchCase = true;
search.query("document");
app.execMenuItem("cmd.addAnnotsBySearchResult.highlight");
- will not annotate results because search.query is asynchronous, so it will not wait for the search process to complete. It just starts the background search-task and immediately goes to the following command in the console. It means the execMenuItem will be called too early, before the results appear. It's the reason why I said that you need to wait with that execMenuItem until the search is complete, unfortunately.
HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
-
- User
- Posts: 18
- Joined: Wed Aug 02, 2023 4:19 pm
Re: Running searches from the JavaScript Console
Vasyl,
Thank you for the information. I may be able to get this to work for me regardless of the asynchronous nature of the search with a wait function. None of my documents are very big and therefore the searches don't take long. I image just putting in a few milliseconds might do the trick. Thanks,
Dustin
Thank you for the information. I may be able to get this to work for me regardless of the asynchronous nature of the search with a wait function. None of my documents are very big and therefore the searches don't take long. I image just putting in a few milliseconds might do the trick. Thanks,
Dustin
- Vasyl-Tracker Dev Team
- Site Admin
- Posts: 2313
- Joined: Thu Jun 30, 2005 4:11 pm
- Location: Canada
Re: Running searches from the JavaScript Console
app.yield(1000); // wait 1 sec
- you may use this one to wait some time..
- you may use this one to wait some time..
Vasyl Yaremyn
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Tracker Software Products
Project Developer
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
-
- User
- Posts: 18
- Joined: Wed Aug 02, 2023 4:19 pm
- TrackerSupp-Daniel
- Site Admin
- Posts: 7696
- Joined: Wed Jan 03, 2018 6:52 pm
Running searches from the JavaScript Console

Daniel McIntyre - Support Technician
Tracker Software Products (Canada) LTD
Support: <Support@tracker-software.com>
Tracker Software Products (Canada) LTD
Support: <Support@tracker-software.com>
-
- User
- Posts: 18
- Joined: Wed Aug 02, 2023 4:19 pm
Re: Running searches from the JavaScript Console
Another question for you if you don't mind...where can I find documentation that lists commands for app level control like you've given an example of above with "app.execMenuItem("cmd.addAnnotsBySearchResult.highlight");" ?
I am assuming that that line is specific pdf xchange editor whereas "search.query" is something I can find in the Adobe PDF API. If I am making any sense here, I would appreciate the direction. thanks,
Dustin
I am assuming that that line is specific pdf xchange editor whereas "search.query" is something I can find in the Adobe PDF API. If I am making any sense here, I would appreciate the direction. thanks,
Dustin
- TrackerSupp-Daniel
- Site Admin
- Posts: 7696
- Joined: Wed Jan 03, 2018 6:52 pm
Re: Running searches from the JavaScript Console
Hello, dustinbagley
The former half of the command "app.execMenuItem" is part of the API manual, as you have found, the Adobe JS API is essentially the go to resource for JS in PDF, while some apps may have varying "security" restrictions on very specific tools, all of these functions should be usable in PDF apps unless intentionally disabled by the developers.
AS for the latter half "cmd.addAnnotsBySearchResult.highlight" This is the Tool ID which can be easily found through the Editor itself. Simply open the customize UI menu (R-click on blank space > Customize UI) then either right click on the tool in question in its toolbar location, and choose properties, or look to the commands tab, and search through the full commands list there. Kind regards,
The former half of the command "app.execMenuItem" is part of the API manual, as you have found, the Adobe JS API is essentially the go to resource for JS in PDF, while some apps may have varying "security" restrictions on very specific tools, all of these functions should be usable in PDF apps unless intentionally disabled by the developers.
AS for the latter half "cmd.addAnnotsBySearchResult.highlight" This is the Tool ID which can be easily found through the Editor itself. Simply open the customize UI menu (R-click on blank space > Customize UI) then either right click on the tool in question in its toolbar location, and choose properties, or look to the commands tab, and search through the full commands list there. Kind regards,
Daniel McIntyre - Support Technician
Tracker Software Products (Canada) LTD
Support: <Support@tracker-software.com>
Tracker Software Products (Canada) LTD
Support: <Support@tracker-software.com>