Some test text!

Loading...
Guides
Signature tool

Signature tool in WebViewer

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. signature modal - draw

  • Text Signatures

Users can choose from one of three colors, as well as different fonts. signature modal - type

  • Image Signatures

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

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

new signature overlay

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:

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

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

  • Ink Signature and Initials

signature and intials  modal - draw

  • Text Signature and Initials

signature modal and initials  - type

  • Image Signature and Initials

signature modal and initials - upload

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

new signature and initials overlay

Importing existing signatures

If you already have a signature stored for the user, you can import them into the signature tool:

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

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

You can also save them by calling exportSignatures.

Importing existing initials

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

You can import 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.

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

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

You can also save them by calling exportInitials.

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 API. Following is an example that adds Tangerine from Google Fonts to the tab.

The css option is not necessary when adding a web safe font.
/* inside stylesheet.css */
@import url('https://fonts.googleapis.com/css2?family=Tangerine&display=swap');
WebViewer({
  ...
  css: 'path/to/stylesheet.css'
}).then(instance => {
  instance.UI.setSignatureFonts(currentFonts => [
    ...currentFonts,
    'Tangerine',
  ]);
});

Export a Signature to Blob Storage

If you have created a Signature and you would like to it store 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.

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);
          })
      })
  });
});

Sample Function to export the Signature

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
    });
}

Get the answers you need: Support

Upcoming Webinar: Customer Experience and Retaining Control: Boosting Document Automation and Efficiency in Financial Services | Sept 15, 2022 at 11 am PT

PDFTron SDK

The Platform

NEW

© 2022 PDFTron Systems Inc. All rights reserved.

Privacy

Terms of Use