> 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/digital-signature/signature-tool.md).

# Use the Digital Signature Tool in WebViewer

Enhance document security with the Signature tool in WebViewer. Easily add ink, text, or image signatures to your files. Preview and choose from various signature types before applying them. The Aprys

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="https://apryse.com/capabilities#DigitalSignature" class="button primary">Package: Digital Signature</a><a href="https://showcase.apryse.com/digital-signatures" class="button primary">Live demo</a>
{% endhint %}

Under the Insert toolbar group, if we select the signature tool, we can click the add signature button which will open the signature modal. Here, users can choose a type of signature and preview it before it is added to the document.

Signatures can be one of three types:

* Ink Signatures

Users can choose from one of three colors.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-c9e73000e00037f1538244f68c28c1b8b9f31be2%2Fddc7e62440c34e247dcee20e4ac0018d5833ae28-600x350.gif?alt=media)

* Text Signatures

Users can choose from one of three colors, as well as different fonts.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-b7b9fb48cc3a7d75357d9d80509b8d412747d1db%2F5704ae6171f4f3d97b56245ef01e53f790692e0b-600x350.gif?alt=media)

* Image Signatures

Users can upload a signature file by dragging and dropping a file, or using the file explorer.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-02846bc5ca7bc0759ce33bd1621f92a942f81e2b%2F942525d853fdd3565e245e0bfa2553b5f003b94b-600x350.gif?alt=media)

If there are any saved signatures, clicking the signature button will open an overlay in which signatures can be chosen and applied directly.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-a13cb2f31e86db51cfea503c1f17c212e78e1634%2Fd759cccb7003da9bd31a52f8b2b8b477494e8b63-600x350.gif?alt=media)

## Initials as Signature

Starting in WebViewer 8.9, the Signature tool supports an additional mode for initials as signatures. This new feature is disabled by default, and can be enabled using the following:

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

```js
WebViewer({
  ...
}).then(instance => {
  instance.UI.enableFeatures([instance.UI.Feature.Initials]);
});
```

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

If this feature is enabled, the signature modal will also require initials to be added.

* Ink Signature and Initials

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-25e94771b568b63677ce17f73a0766404febe467%2F92fc96ddbece753ee1a867d05a86eace78d96e80-600x350.gif?alt=media)

* Text Signature and Initials

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-f388bc3e9de00bbcc09d294180d63e145aa86a91%2F120c7ae448ec5c2f389b078b88105e906c3338d5-600x350.gif?alt=media)

* Image Signature and Initials

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-8fad490052d67be4d911f7f635e4d54748cd29dc%2Fa0df3e70f87aa9056c6300afa7d391737a5c2fe6-600x350.gif?alt=media)

Once created, the signature and intials will be saved in the signatures overlay, allowing users to select between applying signatures or initials.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-3c075b90d0493dc7806b86e7eb918e105151c136%2F6e20b0264e258ae703c1fc4d478e75d145cf9a2f-600x350.gif?alt=media)

## Importing existing signatures

If you already have a signature stored for the user, you can [import](https://sdk.apryse.com/api/web/Core.Tools.SignatureCreateTool.html#importSignatures) them into the signature tool:

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

```js
WebViewer({
  ...
}).then(instance => {
  const { documentViewer } = instance.Core;
  const signatureTool = documentViewer.getTool('AnnotationCreateSignature');

  documentViewer.addEventListener('documentLoaded', () => {
    signatureTool.importSignatures([base64Image]);
  });
});
```

{% endcode %}
{% endtab %}

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

```js
WebViewer({
  ...
}).then(instance => {
  const { docViewer } = instance;
  const signatureTool = docViewer.getTool('AnnotationCreateSignature');

  docViewer.on('documentLoaded', () => {
    signatureTool.importSignatures([base64Image]);
  });
});
```

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

You can also save them by calling [exportSignatures](https://sdk.apryse.com/api/web/Core.Tools.SignatureCreateTool.html#exportSignatures__anchor).

## Importing existing initials

Starting in Webviewer 8.9, you can also import and export initials for a user.

You can [import](https://sdk.apryse.com/api/web/Core.Tools.SignatureCreateTool.html#importInitials) them into the signature tool, which will make them available in the saved signatures overlay. Please note you must have this feature enabled in order to view the saved initials in the viewer.

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

```js
WebViewer({
  ...
}).then(instance => {
  const { documentViewer } = instance.Core;
  const signatureTool = documentViewer.getTool('AnnotationCreateSignature');

  documentViewer.addEventListener('documentLoaded', () => {
    signatureTool.importInitials([base64Image]);
  });
});
```

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

You can also save them by calling [exportInitials](https://sdk.apryse.com/api/web/Core.Tools.SignatureCreateTool.html#exportInitials__anchor).

## Adding custom fonts

By default `GreatVibes` is the only font that is available in the `Type` tab. More fonts can be added using the [setSignatureFonts](https://sdk.apryse.com/api/web/Core.Tools.SignatureCreateTool.html#importSignatures__anchor) API. Following is an example that adds [Tangerine](https://fonts.google.com/specimen/Tangerine/) from Google Fonts to the tab.

{% hint style="info" %}
Google recommends importing fonts in your index.html rather than via CSS for performance reasons. You can read more about Google's recommended methods here: <https://developers.google.com/fonts/docs/css2>
{% endhint %}

Here are two ways to import your fonts in index.html:

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

```css
/* inside <head> of index.html */

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

<link
  href="https://fonts.googleapis.com/css2?family=Tangerine&display=swap"
  rel="stylesheet">

```

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

Or

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

```css
/* inside index.html */

<style>
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400..700&display=swap');
</style>
```

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

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

```js
WebViewer({
  ...
  css: 'path/to/stylesheet.css'
}).then(instance => {
  instance.UI.setSignatureFonts(currentFonts => [
    ...currentFonts,
    'Tangerine',
  ]);
});
```

{% endcode %}
{% endtab %}

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

```js
WebViewer({
  ...
  css: 'path/to/stylesheet.css'
}).then(instance => {
  instance.setSignatureFonts(currentFonts => [
    ...currentFonts,
    'Tangerine',
  ]);
});
```

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

## Export a Signature to Blob Storage

If you have created a Signature and you would like to store it for later use, you can export the Signature as a blob and save it to an external storage solution. If you are on WebViewer 8.9 and have Initials enabled, the following code will also save initials as blobs for storage.

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

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

  documentViewer.addEventListener('annotationsLoaded', async () => {
      annotationManager.addEventListener('annotationSelected', async (annotationList) => {
          annotationList.forEach(annotation => {
              if (annotation.Subject === "Signature")
                  extractAnnotationSignature(annotation, documentViewer);
          })
      })
  });
});
```

{% endcode %}
{% endtab %}

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

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

  docViewer.on('annotationsLoaded', async () => {
      annotManager.on('annotationSelected', async (annotationList) => {
          annotationList.forEach(annotation => {
              if (annotation.Subject === "Signature")
                  extractAnnotationSignature(annotation, docViewer);
          })
      })
  });
});
```

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

Sample Function to export the Signature

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

```js
async function extractAnnotationSignature(annotation, docViewer) {
    // Create a new Canvas to draw the Annotation on
    const canvas = document.createElement('canvas');
    // Reference the annotation from the Document
    const pageMatrix = docViewer.getDocument().getPageMatrix(annotation.PageNumber);
    // Set the height & width of the canvas to match the annotation
    canvas.height = annotation.Height;
    canvas.width = annotation.Width;
    const ctx = canvas.getContext('2d');
    // Translate the Annotation to the top Top Left Corner of the Canvas ie (0, 0)
    ctx.translate(-annotation.X, -annotation.Y);
    // Draw the Annotation onto the Canvas
    annotation.draw(ctx, pageMatrix);
    // Convert the Canvas to a Blob Object for Upload
    canvas.toBlob((blob) => {
        // Call your Blob Storage Upload Function
    });
}
```

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

## Related blogs

["Signature" Signatures - Custom Signing Made Easy](https://apryse.com/blog/webviewer/create-easy-custom-signature-workflows) - 9/29/22


---

# 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/web/digital-signature/signature-tool.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.
