Adding visible digital signatures to a PDF document
Use visible digital signatures to combine visual signoff with cryptographic integrity.
Common use cases include:
- Contract signing workflows
- Approval and authorization systems
- Document authentication pipelines
- Branded signature appearances
Unlike invisible signatures, visible signatures render content in a signature field on the page.
Download sampleHow Nutrient helps
Nutrient Java SDK handles signature field operations, appearance generation, and cryptographic signing.
The SDK handles:
- Parsing signature field dictionaries and appearance stream generation
- Managing PKCS#12 certificate loading and private key extraction
- Handling signature appearance customization and font rendering
- Complex cryptographic signing operations and byte range calculations
Complete implementation
This example adds a visible signature field and signs it with different appearance options:
package io.nutrient.Sample;
import io.nutrient.sdk.Document;import io.nutrient.sdk.types.Color;import io.nutrient.sdk.editors.PdfEditor;import io.nutrient.sdk.editors.pdf.pages.PdfPage;import io.nutrient.sdk.editors.pdf.formfields.PdfSignatureField;import io.nutrient.sdk.signing.PdfSigner;import io.nutrient.sdk.signing.DigitalSignatureOptions;import io.nutrient.sdk.signing.SignatureAppearance;
public class DigitalSignatures {Create the main method as the sample entry point:
public static void main(String[] args) {Creating a signature field
Create a signature field before signing.
In this sample:
- The field name is
ApprovalSignature. - The position is
(100, 700). - The size is
200 × 50.
Save the document after adding the field placeholder:
try (Document document = Document.open("input.pdf")) { PdfEditor editor = PdfEditor.edit(document); PdfPage page = editor.getPageCollection().getFirst();
PdfSignatureField signatureField = editor.getFormFieldCollection().addSignatureField( "ApprovalSignature", page, 100.0f, // left 700.0f, // top 200.0f, // width 50.0f // height );
editor.saveAs("output_document_with_field.pdf"); editor.close(); } catch (Exception e) { System.err.println("Error creating signature field: " + e.getMessage()); }Signing with auto-generated appearance
Sign the field with an auto-generated visible appearance.
In this sample:
Document.open("output_document_with_field.pdf")opens the PDF containing the signature field.DigitalSignatureOptionssets certificate path, password, and signer metadata.setUseAutoGeneratedText(true)generates visible text from metadata.setShowValidationMark(true)adds a validation icon.signField(document, outputPath, fieldName, options, appearance)applies the digital signature and embeds the appearance.
try (PdfSigner signer = new PdfSigner(); Document document = Document.open("output_document_with_field.pdf")) { DigitalSignatureOptions options = new DigitalSignatureOptions(); options.setCertificatePath("certificate.pfx"); options.setCertificatePassword("Nutrient answers all your document needs"); options.setSignerName("John Doe"); options.setReason("Final Approval"); options.setLocation("New York");
SignatureAppearance appearance = new SignatureAppearance(); appearance.setUseAutoGeneratedText(true); appearance.setShowValidationMark(true);
signer.signField( document, "output_signed_visible.pdf", "ApprovalSignature", options, appearance ); } catch (Exception e) { System.err.println("Error signing field: " + e.getMessage()); }Signing with a custom image
Use an image-based appearance for handwritten signatures or logos.
In this sample:
Document.open("output_document_with_field.pdf")opens the PDF before signing.setImagePath(...)sets the signature image.- The image renders inside field bounds.
setShowValidationMark(true)keeps validation marks visible.signField(document, outputPath, fieldName, options, appearance)applies the digital signature.
try (PdfSigner signer = new PdfSigner(); Document document = Document.open("output_document_with_field.pdf")) { DigitalSignatureOptions options = new DigitalSignatureOptions(); options.setCertificatePath("certificate.pfx"); options.setCertificatePassword("Nutrient answers all your document needs"); options.setSignerName("Jane Smith"); options.setReason("Review Complete");
SignatureAppearance appearance = new SignatureAppearance(); appearance.setImagePath("input_signature.jpg"); appearance.setShowValidationMark(true);
signer.signField( document, "output_signed_with_image.pdf", "ApprovalSignature", options, appearance ); } catch (Exception e) { System.err.println("Error signing field: " + e.getMessage()); }Signing with custom text
Use custom text when you need workflow-specific signature content.
In this sample:
Document.open("output_document_with_field.pdf")opens the PDF before signing.setUseAutoGeneratedText(false)disables metadata-generated text.setText(...)sets the visible signature text.\ncreates multiline output.signField(document, outputPath, fieldName, options, appearance)applies the digital signature.
try (PdfSigner signer = new PdfSigner(); Document document = Document.open("output_document_with_field.pdf")) { DigitalSignatureOptions options = new DigitalSignatureOptions(); options.setCertificatePath("certificate.pfx"); options.setCertificatePassword("Nutrient answers all your document needs"); options.setSignerName("Manager");
SignatureAppearance appearance = new SignatureAppearance(); appearance.setUseAutoGeneratedText(false); appearance.setText("Approved by Management\nDate: 2024-01-15");
signer.signField( document, "output_signed_custom_text.pdf", "ApprovalSignature", options, appearance ); } catch (Exception e) { System.err.println("Error signing field: " + e.getMessage()); }Customizing text appearance
Customize typography to match document or brand requirements.
In this sample:
Document.open("output_document_with_field.pdf")opens the PDF before signing.setFontName(...)sets the typeface.setFontSize(...)sets text size.setTextColor(...)applies ARGB color values.signField(document, outputPath, fieldName, options, appearance)applies the digital signature.
try (PdfSigner signer = new PdfSigner(); Document document = Document.open("output_document_with_field.pdf")) { DigitalSignatureOptions options = new DigitalSignatureOptions(); options.setCertificatePath("certificate.pfx"); options.setCertificatePassword("Nutrient answers all your document needs"); options.setSignerName("Executive");
SignatureAppearance appearance = new SignatureAppearance(); appearance.setUseAutoGeneratedText(false); appearance.setText("Approved by Executive Board"); appearance.setFontName("Times New Roman"); appearance.setFontSize(14.0f); appearance.setTextColor(Color.fromArgb(255, 0, 0, 128)); // Navy blue
signer.signField( document, "output_signed_styled_text.pdf", "ApprovalSignature", options, appearance ); } catch (Exception e) { System.err.println("Error signing field: " + e.getMessage()); } }}Conclusion
Use this workflow to add visible digital signatures:
- Open the document using try-with-resources for automatic resource cleanup.
- Create a PDF editor and access the page collection.
- Add a signature field with
addSignatureField()specifying the name, page, position (x, y), and dimensions (width, height). - Save the document with the signature field placeholder.
- Configure
DigitalSignatureOptionswith the certificate path, password, signer name, reason, and location. - Create a
SignatureAppearanceobject to control visual presentation. - Use
setUseAutoGeneratedText(true)for automatic signature text generation from metadata. - Use
setImagePath()to embed custom signature images or logos. - Use
setText()withsetUseAutoGeneratedText(false)for custom text content. - Customize typography using
setFontName(),setFontSize(), andsetTextColor()with ARGB values. - Use
setShowValidationMark(true)to display validation checkmarks. - Call
signField()to perform cryptographic signing and embed appearance.
For related signing workflows, refer to the Java SDK guides.