PDF Editing Issues

How to Select the Pencil Tool and Set Line Color Using Adobe JavaScript

Maira MehtabMaira Mehtab Nov 24, 2026 869 views

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.

How to Select the Pencil Tool and Set Line Color Using Adobe JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the Windows Registry Editor

Press Win + R on your keyboard, type 'regedit' in the Run dialog, and press Enter to open the Registry Editor.

2
Navigate to the Acrobat FeatureLockDown Key

In the Registry Editor, go to the following path: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Adobe\Adobe Acrobat\DC\FeatureLockDown\cDefaultExecMenuItems\tWhiteList.

3
Add the Menu Item to the Whitelist

Create a new entry and add 'Annots:Tool:InkMenuItem' to the whitelist to permit JavaScript execution for the Pencil tool.

4
Add JavaScript to the PDF Button

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

Trigger the Pencil Tool via JavaScript and Registry Whitelist
Color Limitation: You cannot set the default drawing color to red using a script. The user will need to manually select the red color from the tool properties before drawing.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official WPS Office website and download the free installation package.
  2. 2. Open Your PDF Document: Launch WPS Office and open your PDF file directly.
  3. 3. Use Built-in Annotation Tools: Navigate to the 'Comment' tab to access and customize the Pen and highlighting tools instantly without any coding.
Easily draw and annotate on PDFs with built-in, customizable ink tools.Fully compatible with Microsoft Office formats (Word, Excel, PowerPoint) and standard PDFs.User-friendly interface that requires no scripting or registry edits.Lightweight and fast, ensuring smooth performance on all devices.
microsoft office alternative - wps office

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.