# Signature Pad Documentation **A jQuery plugin for assisting in the creation of an HTML5 canvas based signature pad. Records the drawn signature in JSON for later regeneration.** --- - [Introduction](#introduction) - [Demos](#demos) - [Demo of accepting a signature](https://thomasjbradley.github.io/signature-pad/examples/accept-signature.html) - [Demo of requiring a drawn signature](https://thomasjbradley.github.io/signature-pad/examples/require-drawn-signature.html) - [Demo of regenerating a signature](https://thomasjbradley.github.io/signature-pad/examples/regenerate-signature.html) - [Using the Plugin](#using-the-plugin) - [How to Use the Plugin](#how-to-use-the-plugin) - [Javascript](#javascript) - [HTML Template](#html-template) - [Further HTML Explanation](#further-html-explanation) - [Form Submission & Validation](#form-submission--validation) - [Require a Drawn Signature](#require-a-drawn-signature) - [Regenerating Signatures](#regenerating-signatures) - [Regenerating Javascript](#regenerating-javascript) - [Alternate Javascript](#alternate-javascript) - [Regenerating HTML Template](#regenerating-html-template) - [Resizing the Signature Pad](#resizing-the-signature-pad) - [Converting to an Image](#converting-to-an-image) - [Client Side](#client-side) - [Server Side](#server-side) - [Saving to a Database](#saving-to-a-database) - [PHP & MySQL Tutorial](#php--mysql-tutorial) - [Options](#options) - [Changing Default Options](#changing-default-options) - [Options Reference](#options-reference) - [API](#api) - [API Reference](#api-reference) - [API Limitations](#api-limitations) - [Compressing the Output](#compressing-the-output) - [Version History](#version-history) - [License](#license) --- ## Introduction The Signature Pad jQuery plugin will transform an HTML form into a signature pad. The Signature Pad has two modes: TypeIt and DrawIt. In TypeIt mode the user’s signature is automatically generated as HTML text, styled with `@font-face`, from the input field where they type their name. In DrawIt mode the user is able to draw their signature on the canvas element. The drawn signature is written out to a hidden input field as a JSON array using `JSON.stringify()`. Since the signature is saved as JSON it can be submitted as part of the form and kept on file. Using the JSON array, the signature can then be regenerated into the canvas element for display. *Obviously, Signature Pad has a couple extra dependencies: [Douglas Crockford’s json2.js](http://www.json.org/js.html) and [FlashCanvas 1.5](http://flashcanvas.net/). (Both scripts are included in the downloadable package.)* Signature Pad tries to maintain a certain level of progressive enhancement, while still giving developers enough control. There is very little generated HTML. The HTML in the examples has some elements that should be hidden by default (including canvas). Signature Pad will trigger the display of certain items if the browser supports Javascript and canvas. **Signature Pad works with both mouse and touch devices.** Get the source code on GitHub: --- ## Demos [Demo of accepting a signature](https://thomasjbradley.github.io/signature-pad/examples/accept-signature.html)—this demo showcases an HTML form and the Signature Pad ready to accept a new signature. [Demo of requiring a drawn signature](https://thomasjbradley.github.io/signature-pad/examples/require-drawn-signature.html)—this demo showcases an HTML form where the user is required to draw their signature before submission. [Demo of regenerating a signature](https://thomasjbradley.github.io/signature-pad/examples/regenerate-signature.html)—this demo showcases regeneration of a signature from a stored JSON array. --- ## How to Use the Plugin First, include all the required Javascript files: `jquery.js`, `jquery.signaturepad.js`, `flashcanvas.js` and `json2.js`. ```html ``` *Don’t forget to include the flashcanvas.swf file.* And the CSS file: `jquery.signaturepad.css`. ```html ``` The CSS file contains a generic display for the form and Signature Pad, which you are encouraged to change for your web site’s theme. After including all the external resources, simply call the jQuery plugin method on the HTML form element: ```js $('.sigPad').signaturePad(options); ``` The method accepts an options object for the Signature Pad instance. [Signature Pad Options Reference](#options-ref) Calling the `signaturePad()` method also returns an API for the Signature Pad instance. [Signature Pad API Reference](#api-reference) ### Accepting Signatures **[Demo of accepting a signature](https://thomasjbradley.github.io/signature-pad/examples/accept-signature.html)** When accepting a signature, it is best to wrap the Signature Pad in a form so the signature can be submitted to the server for storage. #### Javascript ```js $(document).ready(function () { $('.sigPad').signaturePad(); }); ``` That’s really all there is to it! (`.sigPad` is the class for the form element itself.) Of course there is some corresponding HTML, have a look below for the template. #### HTML Template ```html

Review your signature

Draw your signature

``` This is the HTML used on the accept demo and contains all the bits that Signature Pad looks for. *Remember, all of the class names are configurable [options](#options).* ##### Further HTML Explanation Let’s go through it and explain in detail some of the important parts. ```html ``` The value of the `.name` input element is used for creating the automatically generated signature. ```html

Review your signature

Draw your signature

``` These two paragraphs, `.typeItDesc` and `.drawItDesc` are used as descriptive labels for the canvas Signature Pad. They are hidden or shown depending on whether the user is drawing their signature or using the automatically generated one. ```html