Add eSignatures Using JavaScript

This guide covers how to add an electronic signature (eSignature) to a document, both using the PSPDFKit user interface and programmatically.

Launch Demo

Adding a Signature Programmatically

Electronic signatures are modeled using annotations, so they may sometimes be referred to as signature annotations.

Signatures can be ink or image annotations with the isSignature property set to true. Thus, to programmatically create signatures, you can rely on the existing PSPDFKit.Instance#create method with regular instances of PSPDFKit.Annotations.InkAnnotation or PSPDFKit.Annotations.ImageAnnotation.

Similarly, to update or create electronic signatures, you can use the PSPDFKit.Instance#update and PSPDFKit.Instance#delete methods.

Signature annotations can be created, updated, and deleted if your license includes either the Annotations component or the Electronic Signatures component. If your license includes Electronic Signatures but not Annotations, then signatures are the only type of annotation that can be modified: Modifications to ink or image annotations where isSignature is false, or to annotations of any other type, will be disallowed.

For example, to create an ink signature:

const annotation = new PSPDFKit.Annotations.InkAnnotation({
	pageIndex: 0,
	isSignature: true,
	lines: PSPDFKit.Immutable.List([
		PSPDFKit.Immutable.List([
			new PSPDFKit.Geometry.DrawingPoint({ x: 5, y: 5 }),
			new PSPDFKit.Geometry.DrawingPoint({ x: 95, y: 95 }),
		]),
		PSPDFKit.Immutable.List([
			new PSPDFKit.Geometry.DrawingPoint({ x: 95, y: 5 }),
			new PSPDFKit.Geometry.DrawingPoint({ x: 5, y: 95 }),
		]),
	]),
	boundingBox: new PSPDFKit.Geometry.Rect({
		left: 0,
		top: 0,
		width: 100,
		height: 100,
	}),
});

instance.create(annotation);

For example, to create an image signature:

const request = await fetch('https://example.com/image.jpg');
const blob = await request.blob();
const imageAttachmentId = await instance.createAttachment(blob);
const annotation = new PSPDFKit.Annotations.ImageAnnotation({
	pageIndex: 0,
	isSignature: true,
	contentType: 'image/jpeg',
	imageAttachmentId,
	description: 'Example Image Annotation',
	boundingBox: new PSPDFKit.Geometry.Rect({
		left: 10,
		top: 20,
		width: 150,
		height: 150,
	}),
});

instance.create(annotation);

When the signature creation modal view is shown, the user can add their signature by drawing, selecting an image, or typing.

Using the PSPDFKit User Interface

This guide covers how users can draw a signature on a document using the PDF viewer’s user interface.

If you’re using PSPDFKit with Forms, users can show the signature creation modal view by tapping a signature form field in the document. Without a signature form field, users can add signatures by selecting the signature tool button.

Screenshot of PSPDFKit for Web toolbar with the sign button highlighted.

When the signature creation modal view is shown, the user can add their signature by drawing, selecting an image, or typing. The Draw option allows users to add their signature in their own handwriting as they would on paper. This feels great when using a touchscreen, especially with a stylus such as Apple Pencil.

The Image option allows users to select an existing saved image. This is ideal for use on a user’s main device where they have their files available. With compatible hardware, the user can also take a photo to scan their signature from paper.

The Type option allows users to enter their name and select a signature style. Typing a signature is a safe option in any situation, and it’s the most accessible way to sign: It’s compatible with screen readers such as VoiceOver, TalkBack, NVDA, and JAWS, as well as other accessibility technologies like Switch Control on Mac and iOS. PSPDFKit provides four signature styles out of the box, and your app can easily change the available styles by setting a list of fonts.

With the Draw and Type options, the user can choose between black and two shades of blue, which is useful when it’s necessary for the signature to stand out against the form itself.