API Reference

Complete documentation of all SignSure methods, parameters, and return values.

Constructor

new SignSure(options) Constructor

Creates a new SignSure instance with the specified configuration options.

Parameters

Name Type Required Description
container string Required CSS selector for the container element
licenseKey string Required Your SignSure license key
theme string Optional Theme name: 'default' (embedded), 'dark' (dynamic), 'minimal' (dynamic)
initialScale number Optional Initial zoom level (default: 1.0)
enableNavigation boolean Optional Show page navigation controls (default: true)
enableZoom boolean Optional Enable zoom controls (default: true)
maxFields number Optional Maximum fields per document (default: 50)
allowResize boolean Optional Allow field resizing (default: true)
allowDelete boolean Optional Allow field deletion (default: true)
debug boolean Optional Enable debug logging (default: false)
fieldManagement object Optional Field management options: { selectAll: true, deselectAll: true, clearAll: true }
zoomControls object Optional Zoom controls: { enabled: true, minZoom: 0.25, maxZoom: 5.0, initialZoom: 'auto', zoomStep: 0.25 }
// Basic initialization with default theme (embedded)
const signSure = new SignSure({
    container: '#pdf-container',
    licenseKey: 'your-license-key',
    theme: 'default', // Always available instantly
    initialScale: 1.0,
    enableNavigation: true,
    enableZoom: true,
    maxFields: 50,
    allowResize: true,
    allowDelete: true,
    debug: false,

    // Field management options
    fieldManagement: {
        selectAll: true,     // Enable "Select All Fields" option
        deselectAll: true,   // Enable "Deselect All Fields" option
        clearAll: true       // Enable "Clear All Fields" option
    },

    // Zoom control options
    zoomControls: {
        enabled: true,       // Enable zoom controls in toolbar
        minZoom: 0.25,      // Minimum zoom level (25%)
        maxZoom: 5.0,       // Maximum zoom level (500%)
        initialZoom: 'auto', // 'auto' for best fit, or number for specific zoom
        zoomStep: 0.25,     // Zoom step increment
        fitToWidth: true    // Enable fit to width button
    }
});

// Initialize with dynamic theme (loaded on demand)
const signSureWithDarkTheme = new SignSure({
    container: '#pdf-container',
    licenseKey: 'your-license-key',
    theme: 'dark' // Loaded dynamically when first used
});

// Initialize with minimal theme
const signSureMinimal = new SignSure({
    container: '#pdf-container',
    licenseKey: 'your-license-key',
    theme: 'minimal' // Loaded dynamically when first used
});

Document Management

loadPDF(source) Async

Loads a PDF document from various sources including URLs, File objects, or ArrayBuffers.

Parameters

Name Type Required Description
source string | File | ArrayBuffer Required PDF source: URL string, File object, or ArrayBuffer
Returns

Promise<void> - Resolves when PDF is loaded successfully

// Load from URL
await signSure.loadPDF('https://example.com/document.pdf');

// Load from File input
const fileInput = document.getElementById('file-input');
await signSure.loadPDF(fileInput.files[0]);

// Load from ArrayBuffer
const arrayBuffer = await fetch('document.pdf').then(r => r.arrayBuffer());
await signSure.loadPDF(arrayBuffer);
isDocumentLoaded() Method

Checks if a PDF document is currently loaded.

Returns

boolean - True if document is loaded, false otherwise

if (signSure.isDocumentLoaded()) {
    console.log('Document is ready');
} else {
    console.log('No document loaded');
}
clearDocument() Method

Clears the current document and all associated fields from memory.

signSure.clearDocument();
getDocumentInfo() Method

Returns information about the currently loaded document.

Returns

Object - Document information object

const info = signSure.getDocumentInfo();
console.log(info);
// {
//   numPages: 5,
//   title: "Contract.pdf",
//   author: "John Doe",
//   subject: "Service Agreement",
//   creator: "Adobe Acrobat",
//   producer: "Adobe PDF Library",
//   creationDate: "2024-01-15T10:30:00Z",
//   modificationDate: "2024-01-15T11:45:00Z"
// }

Field Management

addField(fieldOptions) Async

Adds a new form field to the specified page and coordinates.

Parameters

Name Type Required Description
type string Required 'signature', 'initial', 'text', 'date', 'checkbox'
page number Required Page number (1-based)
x number Required X coordinate
y number Required Y coordinate
width number Required Field width
height number Required Field height
required boolean Optional Is field required (default: false)
label string Optional Field label
placeholder string Optional Placeholder text (for text fields)
Returns

Promise<string> - Field ID of the created field

// Add signature field
const fieldId = await signSure.addField({
    type: 'signature',
    page: 1,
    x: 100,
    y: 200,
    width: 200,
    height: 80,
    required: true,
    label: 'Customer Signature'
});

// Add text field
await signSure.addField({
    type: 'text',
    page: 1,
    x: 100,
    y: 300,
    width: 200,
    height: 30,
    required: true,
    label: 'Full Name',
    placeholder: 'Enter your full name'
});
getFields() Async

Returns all fields in the current document.

Returns

Promise<Array> - Array of field objects

const fields = await signSure.getFields();
console.log(fields);
// [
//   {
//     id: 'field-1',
//     type: 'signature',
//     page: 1,
//     x: 100,
//     y: 200,
//     width: 200,
//     height: 80,
//     required: true,
//     label: 'Customer Signature'
//   },
//   // ... more fields
// ]
removeField(fieldId) Async

Removes a field from the document by its ID.

Parameters

Name Type Required Description
fieldId string Required The ID of the field to remove
await signSure.removeField('field-1');
updateField(fieldId, updates) Async

Updates the properties of an existing field.

Parameters

Name Type Required Description
fieldId string Required The ID of the field to update
updates object Required Object containing the properties to update
Returns

Promise<boolean> - True if update was successful

// Update field position and size
await signSure.updateField('field-1', {
    x: 150,
    y: 250,
    width: 300,
    height: 100
});

// Update field label and requirements
await signSure.updateField('field-2', {
    label: 'Updated Label',
    required: true,
    placeholder: 'New placeholder text'
});

// Update field styling
await signSure.updateField('field-3', {
    style: {
        borderColor: '#ff0000',
        backgroundColor: '#fff0f0'
    }
});
selectAllFields() Sync

Selects all existing fields in the document. This will apply selection styling to all fields and emit a fields:allSelected event.

Returns

void

// Select all fields in the document
signSure.selectAllFields();

// Listen for the event
signSure.on('fields:allSelected', (event) => {
    console.log(`Selected ${event.count} fields`);
});
deselectAllFields() Sync

Deselects all currently selected fields in the document. This will remove selection styling from all fields and emit a fields:allDeselected event.

Returns

void

// Deselect all fields in the document
signSure.deselectAllFields();

// Listen for the event
signSure.on('fields:allDeselected', (event) => {
    console.log(`Deselected ${event.count} fields`);
});

Navigate through multi-page PDF documents with these navigation methods.

goToPage(pageNumber) Async

Navigates to the specified page number in the loaded PDF document.

Parameters

Name Type Required Description
pageNumber number Required Page number to navigate to (1-based)
Returns

Promise<boolean> - True if navigation was successful

// Navigate to page 3
await signSure.goToPage(3);

// Navigate to first page
await signSure.goToPage(1);

// Navigate to last page
const totalPages = signSure.getTotalPages();
await signSure.goToPage(totalPages);
getCurrentPage() Method

Returns the current page number being displayed.

Returns

number - The current page number (1-based)

const currentPage = signSure.getCurrentPage();
console.log(`Currently viewing page: ${currentPage}`);
getTotalPages() Method

Returns the total number of pages in the loaded PDF document.

Returns

number - The total number of pages

const totalPages = signSure.getTotalPages();
console.log(`Document has ${totalPages} pages`);

// Create page navigation
for (let i = 1; i <= totalPages; i++) {
    console.log(`Page ${i} available`);
}

Zoom Controls

Control the zoom level and view of PDF documents with these zoom methods.

zoomIn() Sync

Increases the zoom level by the configured zoom step. The zoom level will not exceed the maximum zoom setting.

Returns

void

// Zoom in by one step
signSure.pdfRenderer.zoomIn();

// Or access through hook methods (if using the provided hook)
this.zoomIn();
zoomOut() Sync

Decreases the zoom level by the configured zoom step. The zoom level will not go below the minimum zoom setting.

Returns

void

// Zoom out by one step
signSure.pdfRenderer.zoomOut();

// Or access through hook methods (if using the provided hook)
this.zoomOut();
setZoom(scale) Sync

Sets the zoom level to a specific scale value. The scale will be clamped to the configured minimum and maximum zoom levels.

Parameters

Name Type Required Description
scale number Required Zoom scale (1.0 = 100%, 2.0 = 200%, 0.5 = 50%)
Returns

void

// Set zoom to 150%
signSure.pdfRenderer.setScale(1.5);

// Set zoom to 50%
signSure.pdfRenderer.setScale(0.5);

// Or through hook methods with validation
this.setZoom(1.5);
fitToWidth() Sync

Automatically adjusts the zoom level to fit the PDF width to the container width. This provides optimal viewing for most documents.

Returns

void

// Fit PDF to container width
signSure.pdfRenderer.fitToWidth();

// Listen for zoom changes
signSure.on('scale:changed', (event) => {
    console.log(`Zoom changed to ${Math.round(event.newScale * 100)}%`);
});

Export & Import

Save and restore field configurations with export and import functionality.

📌 Important Note

Export and import methods are accessed through the fieldManager property: signSure.fieldManager.exportConfiguration() signSure.fieldManager.importConfiguration()

exportConfiguration(options) Method

Exports the current field configuration to various formats for saving or sharing.

Parameters

Name Type Required Description
format string Optional Export format: 'json' (default), 'csv'
includeMetadata boolean Optional Include document metadata (default: true)
coordinateFormat string Optional Coordinate system: 'pdf', 'screen', 'pyhanko'
Returns

string | object - Configuration data in the specified format

// Export as JSON (default)
const jsonConfig = signSure.exportConfiguration();
console.log(jsonConfig);

// Export with specific options
const config = signSure.exportConfiguration({
    format: 'json',
    includeMetadata: true,
    coordinateFormat: 'pdf'
});

// Export as CSV
const csvConfig = signSure.exportConfiguration({
    format: 'csv',
    delimiter: ','
});

// Export for PyHanko PDF signing
const pyhankoConfig = signSure.exportConfiguration({
    format: 'json',
    coordinateFormat: 'pyhanko'
});

// Save configuration to file
const configBlob = new Blob([JSON.stringify(jsonConfig)], {
    type: 'application/json'
});
const url = URL.createObjectURL(configBlob);
const a = document.createElement('a');
a.href = url;
a.download = 'signature-fields.json';
a.click();
fieldManager.importConfiguration(config) Method

Imports signature field configurations and creates them at the specified coordinates. Supports multiple formats including arrays of fields, objects with fields property, or single field objects.

Parameters

Name Type Required Description
config Array | Object Required Configuration data to import. Can be:
  • • Array of field objects
  • • Object with "fields" property
  • • Single field object
Required Field Properties

Each field object must include: x, y, width, height

Returns

Array<string> - Array of created field IDs

// Load PDF first
await signSure.loadPDF('document.pdf');

// Method 1: Import array of fields (recommended)
const fields = [
    {
        type: 'signature',
        page: 1,
        x: 100,
        y: 200,
        width: 200,
        height: 80,
        label: 'Client Signature'
    },
    {
        type: 'signature',
        page: 1,
        x: 350,
        y: 200,
        width: 200,
        height: 80,
        label: 'Witness Signature'
    }
];

// Clear existing fields first (optional)
signSure.fieldManager.clearAllFields();

// Import fields
const fieldIds = signSure.fieldManager.importConfiguration(fields);
console.log('Created field IDs:', fieldIds);

// Method 2: Import object with fields property
const config = {
    fields: [
        {
            type: 'signature',
            page: 2,
            x: 50,
            y: 300,
            width: 180,
            height: 70,
            label: 'Manager Approval'
        }
    ]
};
signSure.fieldManager.importConfiguration(config);

// Method 3: Import single field
const singleField = {
    type: 'signature',
    page: 1,
    x: 100,
    y: 400,
    width: 150,
    height: 60,
    label: 'Initial Here'
};
signSure.fieldManager.importConfiguration(singleField);

// Listen for import events
signSure.on('configuration:imported', (data) => {
    console.log(`Imported ${data.importedCount} fields`);
    if (data.errorCount > 0) {
        console.warn(`${data.errorCount} errors occurred`);
        data.errors.forEach(error => console.error(error));
    }
});

// Error handling
try {
    const fieldIds = signSure.fieldManager.importConfiguration(fields);
    console.log('Import successful:', fieldIds);
} catch (error) {
    console.error('Import failed:', error.message);
}
💡 Best Practices
  • • Always load a PDF before importing fields
  • • Use clearAllFields() to remove existing fields before import
  • • Ensure coordinates are within page boundaries
  • • Handle import events for error reporting
  • • Store configurations in database for persistence

Theme Management

SignSure provides dynamic theme management capabilities. The default theme is embedded for instant availability, while additional themes are loaded on-demand for optimal performance.

switchTheme()

Method

Switch to a different theme at runtime. Returns a promise that resolves when the theme is applied.

Parameter Type Required Description
themeName string Required Theme name: 'default', 'dark', 'minimal'
zoomControls object Optional Zoom control configuration: { enabled, minZoom, maxZoom, initialZoom, zoomStep }
fieldManagement object Optional Field management options: { selectAll, deselectAll, clearAll }
initialZoom string|number Optional 'auto' for best fit, or number for specific zoom level (default: 'auto')
// Switch to dark theme
await signSure.switchTheme('dark');

// Switch with options
await signSure.switchTheme('minimal', { preload: true });

// Handle success/failure
const success = await signSure.switchTheme('dark');
if (success) {
    console.log('Theme applied successfully');
} else {
    console.error('Failed to apply theme');
}

getCurrentTheme()

Method

Get the currently active theme name.

Returns Type Description
currentTheme string Name of the currently active theme
const currentTheme = signSure.getCurrentTheme();
console.log('Current theme:', currentTheme); // 'default', 'dark', or 'minimal'

getAvailableThemes()

Method

Get information about all available themes.

Returns Type Description
themes object Object containing theme information with metadata
const availableThemes = signSure.getAvailableThemes();
console.log('Available themes:', Object.keys(availableThemes));

// Example output:
// {
//   default: {
//     name: 'Default',
//     description: 'Clean and professional default theme',
//     embedded: true
//   },
//   dark: {
//     name: 'Dark',
//     description: 'Dark theme for low-light environments',
//     path: './themes/dark.css'
//   },
//   minimal: {
//     name: 'Minimal',
//     description: 'Minimal theme with reduced visual elements',
//     path: './themes/minimal.css'
//   }
// }

preloadThemes()

Method

Preload multiple themes for instant switching. Improves performance when themes are switched frequently.

Parameter Type Required Description
themeNames array Required Array of theme names to preload
// Preload themes for better performance
await signSure.preloadThemes(['dark', 'minimal']);

// Check results
const results = await signSure.preloadThemes(['dark', 'minimal']);
console.log('Preload results:', results);

// Example output:
// {
//   dark: { success: true, error: null },
//   minimal: { success: true, error: null }
// }

enableAutoTheme()

Method

Enable automatic theme switching based on system color scheme preferences.

Parameter Type Required Description
mapping object Optional Theme mapping: { dark: 'themeName', light: 'themeName' }
// Enable auto theme with default mapping
await signSure.enableAutoTheme();

// Custom theme mapping
await signSure.enableAutoTheme({
    dark: 'dark',    // Use dark theme when system prefers dark
    light: 'default' // Use default theme when system prefers light
});

// Check system preference
const themeManager = SignSure.getThemeManager();
const systemScheme = themeManager.getSystemColorScheme();
console.log('System prefers:', systemScheme); // 'dark', 'light', or 'no-preference'

onThemeChange()

Method

Listen for theme change events. Returns an unsubscribe function.

Parameter Type Required Description
callback function Required Callback function to handle theme events
// Listen for theme changes
const unsubscribe = signSure.onThemeChange((event, data) => {
    switch (event) {
        case 'theme-changed':
            console.log(`Theme changed from ${data.from} to ${data.to}`);
            break;
        case 'theme-loaded':
            console.log(`Theme loaded: ${data.theme}`);
            break;
        case 'theme-load-error':
            console.error(`Failed to load theme: ${data.theme}`, data.error);
            break;
        case 'system-theme-change':
            console.log(`System theme changed: prefers dark = ${data.prefersDark}`);
            break;
    }
});

// Unsubscribe when no longer needed
unsubscribe();

// Simple theme change listener
signSure.on('theme-changed', (event) => {
    console.log(`Theme changed to: ${event.theme}`);
});

Event System

SignSure provides an event system to listen for various actions and state changes.

Available Events

pdf:loaded

Fired when a PDF document is successfully loaded

pdf:error

Fired when there's an error loading the PDF

field:added

Fired when a new field is added to the document

field:removed

Fired when a field is removed from the document

field:updated

Fired when a field's properties are updated

on(event, callback) Method

Registers an event listener for the specified event.

Parameters

Name Type Required Description
event string Required The event name to listen for
callback function Required Function to call when the event is fired
// Listen for PDF loaded event
signSure.on('pdf:loaded', () => {
    console.log('PDF is ready!');
});

// Listen for field added event
signSure.on('field:added', (field) => {
    console.log('New field added:', field);
});

// Listen for errors
signSure.on('pdf:error', (error) => {
    console.error('PDF loading failed:', error);
});
off(event, callback) Method

Removes an event listener for the specified event.

Parameters

Name Type Required Description
event string Required The event name to stop listening for
callback function Optional Specific callback to remove (removes all if not provided)
// Remove specific event listener
signSure.off('pdf:loaded', myCallback);

// Remove all listeners for an event
signSure.off('pdf:loaded');

// Remove all listeners for all events
signSure.off();