How to make form elements read only?

If you want to make certain form elements in your document read only you can set the AnnotationFlags.LOCKEDCONTENTS flag on the associated WidgetAnnotation. While the form elements will still be displayed in the document clicking on them won’t start the form editing view making them read only.

Copy
1
2
3
4
5
6
List<FormElement> formElements = document.getFormProvider().getFormElements();
for (FormElement formElement : formElements) {
    // This will prevent the user from making changes to this form element.
    formElement.getAnnotation()
        .setFlags(EnumSet.of(AnnotationFlags.LOCKEDCONTENTS));
}