Some test text!
Web / Guides / Signature tool
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:
Users can choose from one of three colors.
Users can choose from one of three colors, as well as different fonts.
Users can upload a signature file by dragging and dropping a file, or using the file explorer.
If there are any saved signatures, clicking the signature button will open an overlay in which signatures can be chosen and applied directly.
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.
Once created, the signature and intials will be saved in the signatures overlay, allowing users to select between applying signatures or initials.
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.
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.
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.
/* 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',
]);
});
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
});
}
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales