vSignature Documentation

Playground

Introduction

vSignature is a premium, lightweight vanilla JavaScript library built to capture, render, and export high-fidelity hand-drawn signatures on HTML5 canvas elements. It contains vector physics to calculate brush thickness variations dynamically relative to drawing velocity, simulating realistic drawing instruments (e.g. fountain pens, quills, brushes).

The library is fully responsive, dependency-free, and designed to work cleanly inside any framework environment (Laravel, React, Vue, Angular, Node, etc.).

Installation

Install the library into your project dependency manager using npm:

npm install v-signature

Importing Options

Import the ES Module class directly inside your script bundles:

import vSignature from 'v-signature';

Or load using standard CommonJS modular requires:

const vSignature = require('v-signature');

Quick Start

Create a hidden HTML input field where the base64 signature images will be automatically stored during capture:

<input type="hidden" id="signature-data" class="signature">

Initialize the signature capture pad using Javascript:

document.addEventListener('DOMContentLoaded', () => {
    // initialize by passing target input id
    const signature = new vSignature('signature-data');
});

Core Parameters

You can customize the appearance, dimensions, and drawing behaviors by passing configuration parameters in the initialization options:

const signature = new vSignature('signature-data', {
    options: {
        width: '100%',
        height: '350px',
        backgroundColor: '#ffffff',
        border: '1px dashed #cccccc',
        borderRadius: '8px',
        disabled: false
    }
});

Options Properties Table

Option Key Type Default Value Description
width string '100%' width dimension of the canvas signature pad.
height string '300px' height dimension of the canvas signature pad.
color string '#000000' hex or rgba styling value for drawn lines.
backgroundColor string '#f2f2f2' background fill color of the canvas area.
disabled boolean false set true to lock the canvas and disable drawing updates.
lineJoin string 'round' canvas line segment join parameter (round, bevel, miter).
pen string 'default' sets the pointer cursor shape (default, pen, feather, pencil, custom, or a custom image URL).
opacity number 1.0 opacity/transparency level of stroke ink (0.1 to 1.0).

Pen Brush Presets

vSignature supports 5 built-in drawing presets, as well as a fully custom configuration option to define your own dynamic physics:

Preset Value Description
'fountain' / 'pen' velocity-sensitive line thickness mimicking an ink fountain pen.
'quill' / 'feather' fading quill pen with dynamic width and trailing opacity fade-out simulation.
'calligraphy' dynamic calligraphy pen stroke physics.
'gel' smooth, constant thickness solid ink line.
'brush' thick calligraphic brush texture with subtle shadow blur.
'highlighter' translucent, thick highlighter pen drawing style.
'custom' allows manual specification of minWidth, maxWidth, and velocitySensitivity.

Custom Physics Config

const signature = new vSignature('signature-data', {
    options: {
        style: 'custom',
        minWidth: 0.8,              // min thickness at high speeds
        maxWidth: 4.5,              // max thickness at slow speeds
        velocitySensitivity: 0.65   // intensity of velocity transitions
    }
});

Custom Pen Cursor Example

You can customize the mouse cursor shape by providing a custom image URL (such as an ornate green feather quill pen):

const signature = new vSignature('signature-data', {
    options: {
        pen: 'https://png.pngtree.com/png-clipart/20250419/original/pngtree-ornate-green-feather-quill-pen-with-gold-detailing-isolated-png-image_20738981.png'
    }
});

Watermarks & Guidelines

Draw background aids and copyright watermarks directly onto the signature pad at the vector level:

const signature = new vSignature('signature-data', {
    options: {
        // watermark settings
        watermark: 'OFFICIAL USE ONLY',
        watermarkColor: 'rgba(0, 0, 0, 0.05)',
        watermarkFont: '24px sans-serif',
        watermarkAngle: -45,

        // guideline settings
        guideLine: 'Dotted Guideline Title',
        guideLineColor: 'rgba(0, 0, 0, 0.15)',
        guideLineExport: false // do not burn guideline into image exports
    }
});

Public Methods

Interact with the signature pad instance using standard programmatic API methods:

Method Syntax Returns Description
resize() void re-calculates canvas size mapping logic relative to Retina high-DPI scaling.
clear() void erases all stroke data, resets guide lines, and clears data outputs.
undo() void reverts the last captured stroke and redraws the canvas.
redo() void restores the last reverted stroke and redraws the canvas.
disable() void locks canvas interactions, ignoring any new pointer drawings.
enable() void unlocks canvas interactions, accepting new pointer drawings.
isEmpty() boolean returns true if canvas holds zero drawings.
setPen(type) void updates cursor shapes ('default', 'pen', 'feather', 'pencil', 'custom', or a custom image URL string).
on(event, callback) void registers event callback (e.g. 'change', returning new base64 data stream).
toData() Point[][] exports array logs containing raw coordinates and speed physics data.
fromData(data) void imports and renders vector coordinates onto the canvas area.
toPNG() string returns base64 PNG data URL containing the full canvas transparent signature.
downloadPNG() void triggers browser download of the signature as a transparent PNG file.
toJPEG() string returns base64 JPEG data URL containing the full canvas solid white-background signature.
downloadJPEG() void triggers browser download of the signature as a solid white-background JPEG file.
toSVG() string returns the raw inline vector XML <svg> element markup string.
downloadSVG() void triggers browser download of the signature as a vector .svg file.
toTrimmedPNG() string | null returns base64 PNG data URL cropped directly to the bounding boundaries of signature drawing.
downloadTrimmedPNG() void crops signature drawing boundaries and triggers a browser download of a transparent .png file.
toTrimmedJPEG() string | null returns base64 JPEG data URL cropped directly to the bounding boundaries of signature drawing on a solid white background.
downloadTrimmedJPEG() void crops signature drawing boundaries and triggers a browser download of a solid white-background .jpeg file.
toTrimmedSVG() string | null returns cropped vector XML <svg> element markup string using dynamic viewBox cropping.
downloadTrimmedSVG() void crops signature drawing boundaries and triggers a browser download of a vector .svg file.

Callbacks & Events

Bind to changes using the built-in programmatic event listeners:

// bind to change events
signature.on('change', (base64Data) => {
    if (base64Data) {
        console.log('signature captured: ', base64Data);
    } else {
        console.log('signature cleared');
    }
});

License

Released under the standard MIT License. See the LICENSE file for details.