> 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/salesforce/forms/forms/create-signature-field.md).

# Create signature field and signature widget annotation using JavaScript

Learn how to create a new signature field with a required flag and a signature widget annotation in WebViewer 8.9. Enable initials feature for the Signature Widget. Check out our guide for a step-by-s

To create a new signature field with required flag and a signature widget annotation.

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

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

  // myBtn is your own custom button
  document.getElementById('myBtn').addEventListener('click', () => {

    // set flags for required
    const flags = new WidgetFlags();
    flags.set('Required', true);

    // create a form field
    const field = new Annotations.Forms.Field("some signature field name", { 
      type: 'Sig', 
      flags,
    });

    // create a widget annotation
    const widgetAnnot = new Annotations.SignatureWidgetAnnotation(field, {
      appearance: '_DEFAULT',
      appearances: {
        _DEFAULT: {
          Normal: {
            offset: {
              x: 100,
              y: 100,
            },
          },
        },
      },
    });

    // set position and size
    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 50;
    widgetAnnot.Height = 20;

    //add the form field and widget annotation
    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.SignatureWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.SignatureWidgetAnnotation.html#SignatureWidgetAnnotation__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 { annotManager, Annotations } = instance;
  const { WidgetFlags } = Annotations;

  // myBtn is your own custom button
  document.getElementById('myBtn').addEventListener('click', () => {

    // set flags for required
    const flags = new WidgetFlags();
    flags.set('Required', true);

    // create a form field
    const field = new Annotations.Forms.Field("some signature field name", { 
      type: 'Sig', 
      flags,
    });

    // create a widget annotation
    const widgetAnnot = new Annotations.SignatureWidgetAnnotation(field, {
      appearance: '_DEFAULT',
      appearances: {
        _DEFAULT: {
          Normal: {
            data:
              'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjEuMWMqnEsAAAANSURBVBhXY/j//z8DAAj8Av6IXwbgAAAAAElFTkSuQmCC',
            offset: {
              x: 100,
              y: 100,
            },
          },
        },
      },
    });

    // set position and size
    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 50;
    widgetAnnot.Height = 20;

    //add the form field and widget annotation
    annotManager.getFieldManager().addField(field);
    annotManager.addAnnotation(widgetAnnot);
    annotManager.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.SignatureWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.SignatureWidgetAnnotation.html#SignatureWidgetAnnotation__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 %}
{% endtabs %}

## Creating a signature widget to accept initials

Starting in WebViewer 8.9, you can create a Signature Widget that accepts initials. If a signature widget is flagged as `requiresInitials`, it will apply the initials created by the user in the [signature modal](/web/digital-signature/interacting-with-signature-field.md#applying-initials-to-a-signature-field). This optional parameter can be passed when instantiating a Signature Widget. Please note that the initials feature must be enabled in order for this to be displayed in the viewer. For a sample on how to do this refer to [this guide](/web/digital-signature/signature-tool.md#initials-as-signature).

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

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

  // myBtn is your own custom button
  document.getElementById('myBtn').addEventListener('click', () => {

    // set flags for required
    const flags = new WidgetFlags();
    flags.set('Required', true);

    // create a form field
    const field = new Annotations.Forms.Field("some signature field name", { 
      type: 'Sig', 
      flags,
    });

    // create a widget annotation
    const widgetAnnot = new Annotations.SignatureWidgetAnnotation(field, {
      appearance: '_DEFAULT',
      appearances: {
        _DEFAULT: {
          Normal: {
            offset: {
              x: 100,
              y: 100,
            },
          },
        },
      },
      // If this option is passed, the widget will apply any 
      // initials created by the user in the Signature Modal
      requiresInitials: true,
    });
    
    // to show the 'initials' field indicator on widget import
    widgetAnnot.setCustomData('trn-signature-type', 'initialsSignature')

    // set position and size
    widgetAnnot.PageNumber = 1;
    widgetAnnot.X = 100;
    widgetAnnot.Y = 100;
    widgetAnnot.Width = 50;
    widgetAnnot.Height = 20;

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

{% endcode %}
{% endtab %}
{% endtabs %}

[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.SignatureWidgetAnnotation](https://sdk.apryse.com/api/web/Core.Annotations.SignatureWidgetAnnotation.html#SignatureWidgetAnnotation__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)


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/salesforce/forms/forms/create-signature-field.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
