How to Select the Pencil Tool and Set Line Color Using Adobe JavaScript
Question details
The user wants to create interactive buttons in a PDF form using Adobe JavaScript that can instantly select the Pencil (Ink) tool and set its default drawing color to red.

- Product
- Adobe Acrobat
- Device & OS
- Windows
- Scenario
- Creating interactive PDF forms with custom tool selection buttons.
- Observed behavior
- The user needs the correct JavaScript syntax and registry settings to trigger the Pencil tool, and wants to know if setting the default color programmatically is supported.
Ensure you have administrative privileges on your Windows computer, as modifying the registry is required to whitelist the specific Adobe Acrobat menu item for JavaScript execution.
Trigger the Pencil Tool via JavaScript and Registry Whitelist
Use this method to allow a PDF button to execute the Pencil tool menu item by modifying the Windows registry and applying the correct JavaScript code.
Adobe Acrobat restricts certain menu items from being executed via JavaScript for security reasons. To allow a button to select the Pencil (Ink) tool, you must first add the specific menu item to the Acrobat registry whitelist.
Note that Adobe Acrobat JavaScript does not support setting the active tool's drawing color programmatically. Users must manually set the color properties, or you can use a complex script to change the color of the annotations after they are drawn.
Press Win + R on your keyboard, type 'regedit' in the Run dialog, and press Enter to open the Registry Editor.
In the Registry Editor, go to the following path: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Adobe\Adobe Acrobat\DC\FeatureLockDown\cDefaultExecMenuItems\tWhiteList.
Create a new entry and add 'Annots:Tool:InkMenuItem' to the whitelist to permit JavaScript execution for the Pencil tool.
Open your PDF form in Adobe Acrobat, edit the properties of your interactive button, and add the following JavaScript action: app.execMenuItem("Annots:Tool:InkMenuItem");.

Edit and Annotate PDFs Easily with WPS Office
If you are looking for a simpler way to edit, annotate, and manage PDF files without complex JavaScript or registry modifications, try WPS Office. It offers a comprehensive, lightweight, and free alternative to traditional Office and PDF software with seamless format compatibility.
- 1. Download WPS Office: Visit the official WPS Office website and download the free installation package.
- 2. Open Your PDF Document: Launch WPS Office and open your PDF file directly.
- 3. Use Built-in Annotation Tools: Navigate to the 'Comment' tab to access and customize the Pen and highlighting tools instantly without any coding.

Frequently Asked Questions
Can I change the PDF Pencil tool color programmatically using Adobe JavaScript?
No, Adobe Acrobat JavaScript does not support setting or changing the active tool's drawing color programmatically before drawing. Users must set the color manually via the tool properties.
Why does app.execMenuItem not work for the Pencil tool by default?
For security reasons, Adobe Acrobat restricts the execution of certain menu items via JavaScript. You must explicitly add 'Annots:Tool:InkMenuItem' to the registry whitelist under FeatureLockDown to enable it.
Is there any workaround to change the color of drawn lines via script?
Yes, while you cannot set the tool's color beforehand, you can write a complex script to iterate through the annotations after they have been drawn by the user and modify their color properties retroactively.




