Skip to content
How to create a signature appearance with text and image

How to create a signature appearance with text and image

The appearance is built by annotator.NewSignatureField, which takes the signature, a list of text lines, and a SignatureFieldOpts carrying the styling. Set Image on the options to draw a scanned signature or logo alongside the text:

img, _, err := image.Decode(imgFile)
if err != nil {
	return err
}

opts := annotator.NewSignatureFieldOpts()
opts.Rect = []float64{10, 25, 110, 75}
opts.FontSize = 10
opts.Image = img
opts.ImagePosition = annotator.SignatureImageRight
opts.WatermarkImage = watermarkImg

field, err := annotator.NewSignatureField(signature, []*annotator.SignatureLine{
	annotator.NewSignatureLine("Name", "Jane Doe"),
	annotator.NewSignatureLine("Reason", "Approved"),
}, opts)

ImagePosition accepts SignatureImageLeft (the default), SignatureImageRight, SignatureImageTop and SignatureImageBottom. It is ignored when there is no text signature, so an image-only field is just Image plus a Rect, with nil passed for the lines. WatermarkImage is separate and renders behind everything else.

Rect is the trap. NewSignatureFieldOpts fills in a font, a font size of 10 and AutoSize: true, but it leaves Rect empty, and an unset rectangle means the annotation has no area to draw into. A rectangle of {0, 0, 0, 0} is the deliberate way to sign without a visible mark, which is what the document timestamp examples use.

None of this affects the cryptography. The appearance is an annotation on the page; the signature is valid with or without it, and a viewer that renders nothing visible has not necessarily failed to verify.

You can check out our user guide for using UniPDF to create signature appearance fields, and Create Image Appearance for Digital Signature for the image variants.

Last updated on