Create Text Field

Text fields and widget annotations can be added programmatically. There are several properties and widget flags as highlighted below:

Text widget flags

Widget Flag

Description

Unique to text?

READ_ONLY

The field value cannot be changed.

No

REQUIRED

The field must have a value when exported.

No

MULTILINE

The field may contain multiple lines of text.

Yes

COMB

The field shall be automatically divided into as many equally spaced positions as the value of the max length.

Yes

DO_NOT_SCROLL

The field shall not scroll (horizontally for single-line fields, vertically for multiple-line fields) to accommodate more text than fits within its annotation rectangle.

Yes

DO_NOT_SPELL_CHECK

The field text shall not be spell-checked.

Yes

Text widget sample code

1WebViewer(...)
2.then(instance => {
3 const { annotationManager, Annotations, documentViewer } = instance.Core;
4 const { WidgetFlags } = Annotations;
5
6 documentViewer.addEventListener('documentLoaded', () => {
7 // Sets flags for the text widget.
8 const flags = new WidgetFlags();
9 flags.set(WidgetFlags.REQUIRED, true);
10 flags.set(WidgetFlags.MULTILINE, true);
11
12 // Creates a text form field.
13 const field = new Annotations.Forms.Field('TextFormField 1', {
14 type: 'Tx',
15 defaultValue: 'Default Value',
16 flags,
17 });
18
19 // Creates a text widget annotation.
20 const widgetAnnot = new Annotations.TextWidgetAnnotation(field);
21 widgetAnnot.PageNumber = 1;
22 widgetAnnot.X = 100;
23 widgetAnnot.Y = 100;
24 widgetAnnot.Width = 200;
25 widgetAnnot.Height = 50;
26
27 // Add form field to field manager and widget annotation to annotation manager.
28 annotationManager.getFieldManager().addField(field);
29 annotationManager.addAnnotation(widgetAnnot);
30 annotationManager.drawAnnotationsFromList([widgetAnnot]);
31 });
32});

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.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales