Running searches from the JavaScript Console

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: Tracker Support, TrackerSupp-Daniel, 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.
Post Reply
dustinbagley
User
Posts: 22
Joined: Wed Aug 02, 2023 4:19 pm

Running searches from the JavaScript Console

Post by dustinbagley »

In PDF XChange Editor, can I run advanced searches, changes search settings and annotate results from the JavaScript Console? Thanks,

Dustin
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2369
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Running searches from the JavaScript Console

Post by Vasyl-Tracker Dev Team »

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.
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.
dustinbagley
User
Posts: 22
Joined: Wed Aug 02, 2023 4:19 pm

Re: Running searches from the JavaScript Console

Post by dustinbagley »

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
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2369
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Running searches from the JavaScript Console

Post by Vasyl-Tracker Dev Team »

app.yield(1000); // wait 1 sec

- 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.
dustinbagley
User
Posts: 22
Joined: Wed Aug 02, 2023 4:19 pm

Re: Running searches from the JavaScript Console

Post by dustinbagley »

Thank you
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8804
Joined: Wed Jan 03, 2018 6:52 pm

Running searches from the JavaScript Console

Post by TrackerSupp-Daniel »

:)
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
dustinbagley
User
Posts: 22
Joined: Wed Aug 02, 2023 4:19 pm

Re: Running searches from the JavaScript Console

Post by dustinbagley »

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
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8804
Joined: Wed Jan 03, 2018 6:52 pm

Re: Running searches from the JavaScript Console

Post by TrackerSupp-Daniel »

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.
image.png
Kind regards,
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Post Reply