Section:

Filling PDF form fields

You can access and fill any form field by its field id:

1// config.js
2const { documentViewer, annotationManager } = instance.Core;
3
4documentViewer.addEventListener('documentLoaded', () => {
5 documentViewer.getAnnotationsLoadedPromise().then(() => {
6 const fieldManager = annotationManager.getFieldManager();
7 const field = fieldManager.getField(fieldId);
8 field.setValue('new value');
9 });
10});

Iterate over all fields

You can also iterate over all fields using the forEachField function of FieldManager.

Note that you'll need to wait for the annotationsLoadedPromise to resolve to ensure that the fields are accessible in the FieldManager.

1// config.js
2const { documentViewer, annotationManager } = instance.Core;
3
4documentViewer.addEventListener('documentLoaded', () => {
5 documentViewer.getAnnotationsLoadedPromise().then(() => {
6 // iterate over fields
7 const fieldManager = annotationManager.getFieldManager();
8 fieldManager.forEachField(field => {
9 console.log(field.getValue());
10 field.setValue('new value');
11 });
12 });
13});

Listening for field changes

The fieldChanged event is fired any time the value of a form field changes.

1// config.js
2const { annotationManager } = instance.Core;
3
4annotationManager.addEventListener('fieldChanged', (field, value) => {
5 console.log(`Field changed: ${field.name}, ${value}`);
6});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales