Adding visible digital signatures to a PDF document
Adding visible digital signatures to PDFs programmatically enables teams to automate document signing workflows, build approval systems, and implement authentication pipelines. Whether you’re creating automated contract signing systems, building document approval platforms, implementing secure authentication workflows, or creating branded signature experiences, visible signatures provide both visual confirmation and cryptographic proof of authenticity. Unlike invisible signatures, which only embed cryptographic data, visible signatures display signature fields on a document page with customizable appearances, including auto-generated text, custom images, or styled typography.
How Nutrient helps you achieve this
Nutrient Python SDK handles PDF digital signature structures, appearance generation, and cryptographic operations. With the SDK, you don’t need to worry about:
- 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
Instead, Nutrient provides an API that handles all the complexity behind the scenes, letting you focus on your business logic.
Complete implementation
Below is a complete working example that demonstrates adding visible digital signatures to a PDF. The following lines set up the Python application. The import statements bring in all necessary classes from the Nutrient SDK:
from nutrient_sdk import Document, PdfEditor, PdfSigner, Colorfrom nutrient_sdk import DigitalSignatureOptions, SignatureAppearance, TimestampConfigurationfrom nutrient_sdk import SignatureHashAlgorithmCreating a signature field
To add a visible signature, first create a signature field on the document at the desired location. The following code opens the PDF document using a context manager(opens in a new tab) for automatic resource cleanup; creates a PDF editor; accesses the first page; and adds a signature field named "ApprovalSignature" at coordinates (100, 700) with dimensions 200×50 points. This creates a rectangular placeholder where the signature appearance will be rendered after signing. The field position near the top-left of the page (700 points from bottom on letter-size 612×792 paper) provides a common location for approval signatures:
with Document.open("input.pdf") as document: editor = PdfEditor.edit(document) page = editor.page_collection.first
signature_field = editor.form_field_collection.add_signature_field( name="ApprovalSignature", page=page, x=100.0, y=700.0, width=200.0, height=50.0 )
editor.save_as("output_document_with_field.pdf") editor.close()Signing with auto-generated appearance
When signing a field, you can use auto-generated text from the signature metadata to create a standard appearance. The following code uses PdfSigner as a context manager; creates a DigitalSignatureOptions object with certificate credentials; and configures the signing metadata, including signer name, reason, and location. The SignatureAppearance object controls visual rendering, where setting use_auto_generated_text = True instructs the SDK to automatically generate appearance text from the signature metadata (signer name “John Doe”, reason “Final Approval”, location “New York”, and timestamp). The show_validation_mark = True property adds a checkmark or icon indicating signature validity. The sign_field() method signs the "ApprovalSignature" field with the configured options and appearance:
with PdfSigner() as signer: options = DigitalSignatureOptions() options.certificate_path = "certificate.pfx" options.certificate_password = "Nutrient answers all your document needs" options.signer_name = "John Doe" options.reason = "Final Approval" options.location = "New York"
appearance = SignatureAppearance() appearance.use_auto_generated_text = True appearance.show_validation_mark = True
signer.sign_field( "output_document_with_field.pdf", "output_signed_visible.pdf", "ApprovalSignature", options, appearance )Signing with a custom image
Add a handwritten signature image or company logo to make the signature more personal or branded. The following code configures the signature appearance to display a custom image instead of auto-generated text. The image_path property accepts a file path to an image in standard formats (JPEG and PNG), which will be scaled and rendered within the signature field bounds. This pattern is commonly used for handwritten signature scans, executive signatures, or company logos. Combined with show_validation_mark = True, the image appears alongside a validation indicator, providing both visual branding and cryptographic verification in the same signature field:
with PdfSigner() as signer: options = DigitalSignatureOptions() options.certificate_path = "certificate.pfx" options.certificate_password = "Nutrient answers all your document needs" options.signer_name = "Jane Smith" options.reason = "Review Complete"
appearance = SignatureAppearance() appearance.image_path = "input_signature.jpg" appearance.show_validation_mark = True
signer.sign_field( "output_document_with_field.pdf", "output_signed_with_image.pdf", "ApprovalSignature", options, appearance )Signing with custom text
For more control over the appearance, provide custom text instead of auto-generated content. The following code disables auto-generated text by setting use_auto_generated_text = False. It then provides custom text via the text property. The custom text can include multiline content using \n newline characters, enabling formatted approval messages with multiple lines of information. This approach is commonly used for workflow-specific approvals where predefined text templates replace standard signature metadata, such as management approval stamps or quality assurance signoffs:
with PdfSigner() as signer: options = DigitalSignatureOptions() options.certificate_path = "certificate.pfx" options.certificate_password = "Nutrient answers all your document needs" options.signer_name = "Manager"
appearance = SignatureAppearance() appearance.use_auto_generated_text = False appearance.text = "Approved by Management\nDate: 2024-01-15"
signer.sign_field( "output_document_with_field.pdf", "output_signed_custom_text.pdf", "ApprovalSignature", options, appearance )Customizing text appearance
You can also customize the font, size, and color of the signature text to match your branding or requirements. The following code demonstrates complete typography customization by setting font_name to Times New Roman for a formal serif appearance, font_size to 14.0 points for larger text, and text_color using ARGB values (255, 0, 0, 128) to create a navy blue color. The ARGB parameters represent alpha (255 = fully opaque), red (0), green (0), and blue (128), providing precise color control. This customization enables signatures to match corporate brand guidelines or document design requirements:
with PdfSigner() as signer: options = DigitalSignatureOptions() options.certificate_path = "certificate.pfx" options.certificate_password = "Nutrient answers all your document needs" options.signer_name = "Executive"
appearance = SignatureAppearance() appearance.use_auto_generated_text = False appearance.text = "Approved by Executive Board" appearance.font_name = "Times New Roman" appearance.font_size = 14.0 appearance.text_color = Color.from_argb(255, 0, 0, 128) # Navy blue
signer.sign_field( "output_document_with_field.pdf", "output_signed_styled_text.pdf", "ApprovalSignature", options, appearance )Conclusion
The visible digital signature workflow consists of several key operations:
- Open the document using a context manager(opens in a new tab) for automatic resource cleanup.
- Create an editor and access the page collection.
- Add a signature field at specified coordinates with defined dimensions (e.g. 100, 700, 200×50 points).
- The signature field creates a rectangular placeholder for the signature appearance.
- Sign the field using
PdfSignerwith certificate credentials (PKCS#12 format). - Configure signing metadata, including signer name, reason, and location.
- Create the signature appearance with auto-generated text (
use_auto_generated_text = True) to display metadata. - Add validation marks (
show_validation_mark = True) to indicate signature validity. - Use custom images via the
image_pathproperty for handwritten signatures or company logos. - Use custom text with
use_auto_generated_text = Falseand multiline formatting for workflow-specific approvals. - Customize typography with
font_name,font_size, andtext_colorproperties using ARGB values. - Save the signed document with visible signature appearance and cryptographic integrity.
Nutrient handles PDF digital signature structures, PKCS#12 certificate loading, private key extraction, appearance stream generation, signature appearance customization, font rendering, and cryptographic signing operations so you don’t need to understand PDF signature dictionaries or manage byte range calculations manually. The visible signature system provides both visual confirmation and cryptographic proof of authenticity for automated document signing workflows, approval systems, authentication pipelines, and branded signature experiences.