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, in turn making them read-only:

List<FormElement> formElements = document.getFormProvider().getFormElements();
for (FormElement formElement : formElements) {
    // This will prevent the user from making changes to this form element.