Copy link to clipboard
Copied
I have a control that activates the drawing tool in the "onFocus" event. I want to get to the selection tool when the user is done. Is that possible with Javascript / Events?
Yes, there is a way, but there are no events that will provide any kind of direct detection. Instead you have to go about it indirectly. There are two possible solutions.
1. Start an interval timer at the same time you start the drawing tool. Use the timer script to test for a new annotation on the page. Give the timer some maximum time as a safety. Maybe popup a message box to ask the user if they want to continue. I've used this method before and it works well as long as the users are well beh
...Copy link to clipboard
Copied
Maybe, all of the tools are activated by menu items, so the question is, can the menu item for the drawing tool be activated by JavaScript on a form.
The code for running a menu item is
app.execMenuItem();
All you need to test it out is the language independent name of the select tool menu item.
Here is an article on the topic:
https://acrobatusers.com/tutorials/executing_menu_items_from_javascript
You'll find more info here, including a plug-in for finding hidden menu items, of which there are many. There are lots of hidden menu items because Acrobat used to be all menu driven. When they switched the UI to all the fancy panels they never got rid of the menus, just hid them.
Alerts, Popups, and Other Devices for Interacting with the User
Copy link to clipboard
Copied
I already have it activated. My question is how to DEACTIVATE.
Copy link to clipboard
Copied
You deactivate it by selecting another tool. There is always one active, you just have to decide which one you want, for example the Hand tool, which is the default.
app.execMenuItem("Hand");
Copy link to clipboard
Copied
You should really avoid using "execMenuItem". The existence of the menu items and their names are highly dependent on the Acrobat version. You won't be able to count on that menu item being available or in the same location in future releases.
Rethink your use case.
Copy link to clipboard
Copied
Well Actually, the menu items never really go away. Do you have my Hidden Menu Items plug-in? Download it from the link I provided above. There's stuff in there going way back, and it still works.
However I get you're point. It's like using undocumented code. But just about any code these days is a problem because of all the 3rd party viewers, especially on mobile.
Copy link to clipboard
Copied
That's all true but I'm still going to recommend the questioner rethink their solution. As the mobile viewers get more script enabled, you won't be able to rely on the menu items being there.
Copy link to clipboard
Copied
Joel_Geraci,
We are controlling the user environment because users are coming to our machine to fill out the forms.
Copy link to clipboard
Copied
How would you enable the Hand tool via Javascript? It would have to be in an event listener. What event could you attach it to?
Copy link to clipboard
Copied
The only events you can use in Acrobat are related to form fields, bookmarks or links, or when a file is opened, closed, saved or printed, and when the application is first opened.
Copy link to clipboard
Copied
Yes, there is a way, but there are no events that will provide any kind of direct detection. Instead you have to go about it indirectly. There are two possible solutions.
1. Start an interval timer at the same time you start the drawing tool. Use the timer script to test for a new annotation on the page. Give the timer some maximum time as a safety. Maybe popup a message box to ask the user if they want to continue. I've used this method before and it works well as long as the users are well behaved.
2. Recreate the drawing tool in JS so you control it. This works well for circle and rectangle annots. What you do is create a page size invisible button. Use the button to detect mouse up and mouse down events. On mouse down create a circle or square annot at the mouse point. Start a timer to pick up the inbetween movements for drawing out the circle or square, then use Mouse up to kill the timer.
The #2 method is more reliable, but requires more coding on your part.