Some test text!

Search
Hamburger Icon

Salesforce / Guides / Signature

Signature Annotation in WebViewer Salesforce

Requiring signed documents isn't unfamiliar to Salesforce, Apryse SDK provides an intuitive UI tool for placing custom or hand-drawn signatures onto pdfs. Clicking the signature button in the header will open the signature dialog immediately. Users can also choose to save the signature and preview it before being drawn on the document.

Signatures can be created by:

  • drawing

signature modal - draw

  • typing

signature modal - type

  • uploading an image

signature modal - uploading

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

Importing existing signatures

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

// Config file
const { documentViewer } = instance.Core;
const signatureTool = documentViewer.getTool('AnnotationCreateSignature');

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

You can also save them by calling exportSignatures.

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 constructor
WebViewer({
  ...
  css: 'path/to/stylesheet.css'
})

// Config file
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.

// Config file
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
    });
}

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales