1WebViewer(...)
2.then(instance => {
3 const { annotManager, Annotations } = instance;
4
5 // myBtn is your own custom button
6 document.getElementById('myBtn').addEventListener('click', () => {
7
8 // set flags for combo box
9 const flags = new Annotations.WidgetFlags();
10 flags.set(WidgetFlags.COMBO, true);
11
12 // create combo options
13 const options = [
14 {
15 value: '1',
16 displayValue: 'one'
17 },
18 {
19 value: '2',
20 displayValue: 'two'
21 }
22 ];
23
24 // create a form field
25 const field = new Annotations.Forms.Field("some combo box field name", {
26 type: 'Ch',
27 value: options[0].value,
28 flags,
29 options
30 });
31
32 // create a widget annotation
33 const widgetAnnot = new Annotations.ChoiceWidgetAnnotation(field);
34
35 // set position and size
36 widgetAnnot.PageNumber = 1;
37 widgetAnnot.X = 100;
38 widgetAnnot.Y = 100;
39 widgetAnnot.Width = 50;
40 widgetAnnot.Height = 20;
41
42 //add the form field and widget annotation
43 annotManager.getFieldManager().addField(field);
44 annotManager.addAnnotation(widgetAnnot);
45 annotManager.drawAnnotationsFromList([widgetAnnot]);
46 });
47});