Create Combobox Fields
Combobox (choice) fields and widget annotations can be added programmatically. There are several properties and widget flags as highlighted below:
Combobox widget flags
Widget flag
Description
Unique to combobox?
READ_ONLY
The field value cannot be changed.
No
REQUIRED
The field must have a value when exported.
No
COMBO
The field is a combobox. Must be true.
No
MULTI_SELECT
The field can have multiple selected values.
No
EDIT
If true, the combobox will include an editable text box with a dropdown.
Yes
Combobox sample code
WebViewer(...)
.then(instance => {
const { annotationManager, Annotations, documentViewer } = instance.Core;
const { WidgetFlags } = Annotations;
documentViewer.addEventListener('documentLoaded', () => {
// Sets flags for the combobox widget.
const flags = new WidgetFlags();
flags.set(WidgetFlags.COMBO, true);
flags.set(WidgetFlags.REQUIRED, true);
// Define the available options.
const comboOptions = [
{ value: '1', displayValue: 'one' },
{ value: '2', displayValue: 'two' },
{ value: '3', displayValue: 'three' }
];
// Specify a font-family and font size.
const font = new Annotations.Font({ name: 'Helvetica', size: 12 });
// Creates a combobox form field.
const field = new Annotations.Forms.Field('ComboBoxField 1', {
flags,
font,
type: 'Ch',
options: comboOptions,
value: comboOptions[0].value,
});
// Creates a combobox widget annotation.
const widgetAnnot = new Annotations.ChoiceWidgetAnnotation(field);
widgetAnnot.PageNumber = 1;
widgetAnnot.X = 100;
widgetAnnot.Y = 100;
widgetAnnot.Width = 200;
widgetAnnot.Height = 25;
// Add form field to field manager and widget annotation to annotation manager.
annotationManager.getFieldManager().addField(field);
annotationManager.addAnnotation(widgetAnnot);
annotationManager.drawAnnotationsFromList([widgetAnnot]);
});
});Learn More
Annotations and fields should be added to the document only after the document has finished loading. See Create New Form Fields Overview for more.
Last updated
Was this helpful?