Q: Can I set all fields to Read Only using Javascript so that they can’t be modified?

A:  YES, PDF Studio supports setting form fields to read only (preventing modification) through JavaScript. Below is an example showing a button with JavaScript action to set all fields within a document to Read only.

1. Create a Push Button

2. Right click on the Button -> Properties -> select Actions

3. Select Add -> select JavaScript action from “Action” list

4. Copy and paste the following code

for (var i = 0; i < this.numFields; i++) {
        this.getField(getNthFieldName(i)).readonly=true;
    }

JavaScript2

5. Click OK to apply the changes to the button and the document.

When the button is clicked, it will set all fields in the document to Read Only. This can be added either by itself or in combination with other JavaScript actions if needed.

NOTEFields will be set to read only but the document will need to be Saved in order to maintain the changes. If the document is not saved, the next time the document is opened the fields will return back to their original state.