Modifying PDF form fields
The following code sets all fields to readonly when the document is loaded. The annotationChanged event is triggered when the annotations are added to the document and checking the action and e.imported ensures that they changed because of an import into the document and not because of a user modification.
// config.js
const { annotationManager, Annotations } = instance.Core;
annotationManager.addEventListener('annotationChanged', (annotations, action, { imported }) => {
// if the annotation change occurs because of an import then
// these are fields from inside the document
if (imported && action === 'add') {
annotations.forEach(function(annot) {
if (annot instanceof Annotations.WidgetAnnotation) {
annot.fieldFlags.set('ReadOnly', true);
}
});
}
});// config.js
const { docViewer, annotManager, Annotations } = instance;
annotManager.on('annotationChanged', (annotations, action, { imported }) => {
// if the annotation change occurs because of an import then
// these are fields from inside the document
if (imported && action === 'add') {
annotations.forEach(function(annot) {
if (annot instanceof Annotations.WidgetAnnotation) {
annot.fieldFlags.set('ReadOnly', true);
}
});
}
});Iterate over all fields
You can iterate over all fields using the forEachField function of FieldManager.
Accessing fields by name
You can access any field by its field name:
Last updated
Was this helpful?