Edit PDF Form Fields Using JavaScript

To programmatically update a form field or a widget annotation, you can use the instance.update() method. You can also use it to change the widget annotations associated with the form field. It’s also possible to edit form fields using the built-in user interface.

The following example retrieves and updates a form field and its associated widget annotation:

const formFields = await instance.getFormFields();
const formField = formFields.find(
  (formField) => formField.name === "my form field"
);
const annotations = await instance.getAnnotations(0);
const widget = annotations.find(
  (annotation) => annotation.formFieldName === "my form field"
);
await instance.update([
  formField.set("required", true),
  widget.set("opacity", 0.5)
]);