PDF Editing Issues

How to Make PDF Form Fields Read-Only After Signing with JavaScript

Maira MehtabMaira Mehtab Nov 5, 2026 869 views

Question details

The user wants to secure dynamically generated PDF forms by making specific groups of text fields read-only automatically once the associated signature field is signed.

How to Make PDF Form Fields Read-Only After Signing with JavaScript
Product
PDF
Device & OS
not provided
Scenario
Creating interactive PDF forms where partial or grouped field locking is required immediately upon capturing a digital signature.
Observed behavior
Text fields remain editable after signing unless explicitly locked. The goal is to programmatically restrict editing using JavaScript once a signature is applied.
Before you start

Before applying JavaScript to your PDF, ensure that all the target text fields and signature fields have already been created and correctly named in your document, as the script requires the target fields to exist beforehand.

Solution 1Recommended

Lock Specific Form Fields Using JavaScript setLock Method

Use the setLock method in the signature properties to automatically lock an array of specified text fields when a digital signature is applied.

This method is ideal when you have specific groups of fields that need to be secured immediately after a user signs.

Ensure that all fields listed in your JavaScript array already exist in the PDF before executing the code. If a specified field is missing, the locking action will fail to trigger.

1
Open form editing mode

Open your PDF editor and enter the Form Editing mode to access field properties.

2
Access signature properties

Right-click the targeted Signature field and select 'Properties' from the context menu.

3
Navigate to the Signed tab

In the Properties dialog box, go to the 'Signed' tab which controls actions triggered upon signing.

4
Input the JavaScript code

Choose the option to run a custom JavaScript and input: this.getField("Signature1").setLock({ action: "Include", fields: ["Text1", "Text2", "Text3"] }); replacing the field names with your actual document fields.

5
Save and test

Save the PDF document and test the signature to ensure the specified fields successfully become read-only.

Lock Specific Form Fields Using JavaScript setLock Method
Field Names Must Match: The field names in your JavaScript array must exactly match the names of the text fields configured in your PDF form. They are case-sensitive.
Secure and Edit PDFs Effortlessly

Manage PDF Form Fields Easily with WPS Office

WPS Office provides robust PDF editing capabilities, allowing you to create interactive forms, add digital signatures, and manage field properties seamlessly without complex coding.

  1. 1. Open your document: Launch WPS Office and open your PDF document.
  2. 2. Access form tools: Navigate to the 'Form' tab on the top ribbon to insert text fields and signature fields.
  3. 3. Configure field properties: Double-click any field to access its properties, set names, and configure protection or formatting settings.
  4. 4. Save and share: Save your finalized interactive PDF and share it securely with clients or colleagues.
Easily create, edit, and fill interactive PDF forms.Add secure digital signatures to protect your document integrity.Fully compatible with standard PDF formats and Adobe Acrobat interactive features.Lightweight software with an intuitive, user-friendly interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my JavaScript failing to lock the PDF form fields after signing?

This usually happens if the text fields specified in your JavaScript do not exist yet when the action is configured, or if there is a typo in the field names. Double-check that all field names in the script exactly match the ones created in your document, keeping in mind that they are case-sensitive.

Can I unlock the fields after they have been set to read-only?

Once a document is signed and the script sets the fields to read-only, they are locked to preserve the integrity of the signature. To make them editable again, you would typically need to clear or invalidate the digital signature first.

Does the setLock method work in all PDF readers?

The setLock method relies on standard PDF JavaScript API support. While it works perfectly in major PDF editors like WPS Office and Adobe Acrobat, some basic or built-in web browser PDF viewers might not fully support JavaScript execution, which can prevent the locking action from occurring.

How do I lock all fields in a PDF instead of just specific ones?

If you want to lock the entire document, you can change the action in the setLock method to 'All', using the script: this.getField("Signature1").setLock({ action: "All" });. Alternatively, you can use the built-in 'Mark as Read-Only' option found directly in standard signature properties without writing any code.