Read-only Forms

Q: How can I make form fields read-only?

You could get to a situation where you want to restrict editing to all or only a few selected form fields. You can do so by setting form field’s property readOnly to true:

// Retrieve all form fields from the document.
const formFields = await instance.getFormFields();

// Set `readOnly` flag on each form field.
const updatedFormFields = => it.set('readOnly', true));

// Update the form fields.
await instance.update(updatedFormFields);

If you don’t have the Form Creator license, you can’t change the behavior of actual form fields. In that case, you can apply client side restrictions to make the form fields read-only using isEditableAnnotation:

  // ... otherOptions
  isEditableAnnotation: function(ann) {
    return !(ann instanceof PSPDFKit.Annotations.WidgetAnnotation)

If you want to do this after PSPDFKit has loaded, you can use instance.setIsEditableAnnotation instead.

This has been tested with PSPDFKit for Web 2021.1.0.