How to Run JavaScript When a PDF Signature Field is Signed
Question details
The user wants to automatically populate a date field when a recipient signs a PDF document created via Excel VBA and Acrobat.

- Product
- Adobe Acrobat, Excel VBA
- Device & OS
- not provided
- Scenario
- Automating PDF workflows where a date field needs to be filled automatically upon the execution of a digital signature.
- Observed behavior
- Looking for a method to trigger a script to auto-fill the date field when a signature field generates an event in a PDF.
Ensure you have Adobe Acrobat Professional installed to develop and test your JavaScript code before integrating it with your Excel VBA project.
Use Acrobat JavaScript to Trigger a Keystroke Event
Assign an event script to the signature field using the Field.setAction() method to populate the date field upon signing.
When a PDF signature field is signed, it generates a keystroke event. You can use a keystroke event script to set the date field, just as you would with the Signed script in the signature field properties.
It is highly recommended to develop the script first in Acrobat Professional to ensure the logic works correctly, and then integrate it with your VBA workflow.
In Adobe Acrobat Professional, create an Acrobat folder-level function to house all your reusable PDF feature scripts. This ensures the functions are globally accessible when called.
Use the Field.setAction() method within your script to assign a keystroke event to the target signature field.
Write the keystroke event script so that it targets your specific date field and populates it with the current date when the signature keystroke event is detected.
In your Excel VBA script, use the Acrobat API (AcroExch) to execute the folder-level JavaScript function you created, applying the behavior to the newly generated PDF.

Edit and Sign PDFs Effortlessly with WPS Office
While scripting with Excel VBA and Acrobat can be highly complex, WPS Office provides a streamlined, built-in PDF editor that makes adding signatures, text fields, and dates simple and intuitive without requiring advanced coding skills.
- 1. Open your PDF: Launch WPS Office and open your PDF document using the built-in PDF editor.
- 2. Access the signing tools: Navigate to the 'Fill & Sign' or 'Protect' tab located on the top ribbon.
- 3. Add your signature: Click on 'Sign' to create a new digital signature or insert an existing one into the designated document field.
- 4. Insert the date manually: Use the 'Add Text' tool to easily input the current date next to your signature, bypassing the need for complex JavaScript event listeners.

Frequently Asked Questions
What event is triggered when a PDF signature field is signed?
When a PDF signature field is signed, it inherently generates a keystroke event in Acrobat. You can bind a JavaScript function to this specific event to execute subsequent actions, such as auto-filling a date field.
Where should I develop my Acrobat JavaScript before using VBA?
It is highly recommended to develop and test your JavaScript directly inside Adobe Acrobat Professional first. Once verified, you can place the reusable functions into an Acrobat folder-level script and call them seamlessly via Excel VBA.
Can I use VBA to directly manipulate PDF fields without JavaScript?
While Excel VBA can interact with the Acrobat application via the AcroExch API to extract or set basic data, configuring dynamic field-level event triggers (like actions upon signing) typically requires injecting or calling Acrobat JavaScript.




