Adding electronic signatures to PDFs on Android

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

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 create instances of InkAnnotation or StampAnnotation, call setIsSignature(true) on them, and add them to the document via PdfFragment#addAnnotationToPage().

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:

val pdfFragment: PdfFragment = ...

// Create the ink annotation.
val annotation = InkAnnotation(0)

// Set the line color and width.
annotation.color = Color.RED
annotation.lineWidth = 3f

// Set the stroke data. For example, this would be loaded from user input on another device.
// This example code is just hardcoding a stroke with three points.
val line = listOf(
    PointF(100f, 100f),
    PointF(150f, 150f),
    PointF(200f, 100f)
)
annotation.lines = listOf(line)

// Mark this ink annotation as a signature.
annotation.setIsSignature(true)

// Add it to the page.
pdfFragment?.addAnnotationToPage(annotation, false)
final PdfFragment pdfFragment = ...

// Create the ink annotation.
final InkAnnotation annotation = new InkAnnotation(0);

// Set the line color and width.
annotation.setColor(Color.RED);
annotation.setLineWidth(3f);

// Set the stroke data. For example, this would be loaded from user input on another device.
// This example code is just hardcoding a stroke with three points.
final List<PointF> line = Arrays.asList(
    new PointF(100, 100),
    new PointF(150, 150),
    new PointF(200, 100)
);
annotation.setLines(Collections.singletonList(line));

// Mark this ink annotation as a signature.
annotation.setIsSignature(true);

// Add it to the page.
getPdfFragment().addAnnotationToPage(annotation, false);

For example, to create an image signature:

val pdfFragment: PdfFragment = ...
val bitmap = BitmapFactory.decodeFile("my-signature.png")

// Create the image annotation.
val annotation = StampAnnotation(0, RectF(50f, 440.0f, 500f, 0.0f), bitmap)

// Mark this image annotation as a signature.
annotation.setIsSignature(true)

// Add it to the page.
pdfFragment?.addAnnotationToPage(annotation, false)
final PdfFragment pdfFragment = ...
final Bitmap bitmap = BitmapFactory.decodeFile("my-signature.png");

// Create the image annotation.
final StampAnnotation annotation = new StampAnnotation(0,
    new RectF(100, 100, 300, 140),
    bitmap);

// Mark this image annotation as a signature.
annotation.setIsSignature(true);

// Add it to the page.
getPdfFragment().addAnnotationToPage(annotation, false);

Using the PSPDFKit 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. If your license includes Annotations, then the signature tool can be found with the other annotation tools.

Android screenshot showing annotation toolbar with the second group expanded to show the highlighted signature icon.

Without Annotations, the signature tool will be included directly in the main toolbar by default. This button can also be added using forceSignatureButtonPositionInMainToolbar in the PdfActivityConfiguration.Builder.

Android screenshot showing main toolbar with the signature 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 is especially suited to using a touchscreen and stylus.

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.