Skip to main content
Inspiring
March 13, 2018
解決済み

Using Javascript, how do I deactivate the drawing tool?

  • March 13, 2018
  • 返信数 1.
  • 1323 ビュー

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?

このトピックへの返信は締め切られました。
解決に役立った回答 Thom Parker

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?


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.

返信数 1

Thom Parker
Community Expert
Community Expert
March 13, 2018

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

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
March 13, 2018

I already have it activated. My question is how to DEACTIVATE.

Thom Parker
Community Expert
Community Expert
March 13, 2018

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

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often