> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/forms/forms/create-text-field.md).

# Create Text Field

Learn how to create new PDF text form fields using JavaScript with WebViewer. The Apryse Web SDK streamlines secure, serverless document processing with robust support for JavaScript and TypeScript, a

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

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
.then(instance => {
  const { annotationManager, Annotations, documentViewer } = instance.Core;
  const { WidgetFlags } = Annotations;

  documentViewer.addEventListener('documentLoaded', () => {
    // Sets flags for the text widget.
    const flags = new WidgetFlags();
    flags.set(WidgetFlags.REQUIRED, true);
    flags.set(WidgetFlags.MULTILINE, true);

    // Creates a text form field.
    const field = new Annotations.Forms.Field('TextFormField 1', {
      type: 'Tx',
      defaultValue: 'Default Value',
      flags,
    });

    // Creates a text widget annotation.
    const widgetAnnot = new Annotations.TextWidgetAnnotation(field);
    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 200;
    widgetAnnot.Height = 50;

    // Add form field to field manager and widget annotation to annotation manager.
    annotationManager.getFieldManager().addField(field);
    annotationManager.addAnnotation(widgetAnnot);
    annotationManager.drawAnnotationsFromList([widgetAnnot]);
  });
});
```

{% endcode %}

[Annotations.WidgetFlags](https://sdk.apryse.com/api/web/Core.Annotations.WidgetFlags.html) [Annotations.Forms.Field](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html) [Annotations.TextWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.TextWidgetAnnotation.html#TextWidgetAnnotation__anchor) [Annotations.WidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html) [AnnotationManager.addAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#addAnnotation__anchor) [AnnotationManager.drawAnnotationsFromList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#drawAnnotationsFromList__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.addField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#addField__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    const { docViewer, annotManager, Annotations } = instance;

    docViewer.on('documentLoaded', () => {
      // create field and widget annotations here
    });
  });
```

{% endcode %}

[DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor)
{% endtab %}
{% endtabs %}

#### Learn More

Annotations and fields should be added to the document only after the document has finished loading. See [Create New Form Fields Overview](/web/forms/create-fields.md) for more.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/web/forms/forms/create-text-field.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
