Section:

Create combo box field and choice widget annotation using JavaScript

To create a new combo box field and a choice widget annotation.

JavaScript

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});

Create fillable PDF forms
Full sample code demonstrating how to add form fields to a PDF. Fields are first added as annotations and then converted to interactive form fields. Add signatures, text fields, checkboxes.

Available widget flags are:

  • ReadOnly
  • Required
  • NoExport
  • Multiline
  • Password
  • NoToggleToOff
  • Radio
  • PushButton
  • Combo
  • Edit
  • DoNotScroll
  • RadiosInUnison

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales