Section:

Create text field and text widget annotation using JavaScript

To create a new text field with multi-line required flags and a text widget annotation.

1WebViewer(...)
2.then(instance => {
3 const { annotationManager, Annotations } = instance.Core;
4 const { WidgetFlags } = Annotations;
5
6 // myBtn is your own custom button
7 document.getElementById('myBtn').addEventListener('click', () => {
8
9 // set flags for multiline and required
10 const flags = new WidgetFlags();
11 flags.set('Multiline', true);
12 flags.set('Required', true);
13
14 // create a form field
15 const field = new Annotations.Forms.Field("some text field name", {
16 type: 'Tx',
17 defaultValue: "some placeholder default text value",
18 flags,
19 });
20
21 // create a widget annotation
22 const widgetAnnot = new Annotations.TextWidgetAnnotation(field);
23
24 // set position and size
25 widgetAnnot.PageNumber = 1;
26 widgetAnnot.X = 100;
27 widgetAnnot.Y = 100;
28 widgetAnnot.Width = 50;
29 widgetAnnot.Height = 20;
30
31 //add the form field and widget annotation
32 annotationManager.getFieldManager().addField(field);
33 annotationManager.addAnnotation(widgetAnnot);
34 annotationManager.drawAnnotationsFromList([widgetAnnot]);
35 });
36});

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