Provides functionality for signing PDF documents. Supports both digital signatures (with certificate) and electronic signatures (visual only).
The Signature class enables adding signatures to PDF documents: Digital signatures use PFX/P12 certificates to cryptographically sign the document.Electronic signatures add visual representation (image/text) without cryptographic signing. For PAdES-B compliance, use CAdES signature mode (the default). For PAdES-T compliance, configure a TimestampConfiguration in the signature options.
from nutrient_sdk import SignatureConstruction
Signature()Creates a new Signature instance with default settings.
Methods
add_document_timestamp
def add_document_timestamp(self, document: Document, output_path: str, timestamp: TimestampConfiguration) -> NoneAppends a document timestamp to a document, protecting its current state and its validation material.
Parameters:
| Name | Type | Description |
|---|---|---|
document | Document | The document to timestamp. |
output_path | str | The path where the updated PDF will be saved. |
timestamp | TimestampConfiguration | The timestamp authority configuration. |
add_ltv_information
def add_ltv_information(self, document: Document, output_path: str) -> NoneAdds long-term validation material — certificates and revocation information — for all signed signatures of a document, upgrading it toward PAdES B-LT.
Parameters:
| Name | Type | Description |
|---|---|---|
document | Document | The signed document to add validation material to. |
output_path | str | The path where the updated PDF will be saved. |
finish_signature
def finish_signature(self, prepared_document: Document, output_path: str, signed_data: list, options: DigitalSignatureOptions) -> NoneCompletes external signing (phase two) with a raw signature value produced by an external signer.
Parameters:
| Name | Type | Description |
|---|---|---|
prepared_document | Document | The prepared document returned by PrepareSignature. |
output_path | str | The path where the signed PDF will be saved. |
signed_data | list | The raw signature value over the prepared bytes. |
options | DigitalSignatureOptions | The digital signature options with the same certificate used to prepare. |
finish_signature_with_cms
def finish_signature_with_cms(self, prepared_document: Document, output_path: str, signature_container: list) -> NoneCompletes external signing (phase two) with a complete signature container produced by an external signing service.
Parameters:
| Name | Type | Description |
|---|---|---|
prepared_document | Document | The prepared document. |
output_path | str | The path where the signed PDF will be saved. |
signature_container | list | The complete, DER-encoded CMS signature container. |
prepare_signature
def prepare_signature(self, document: Document, output_path: str, options: DigitalSignatureOptions) -> listStarts external signing (phase one): prepares the document with a signature placeholder and returns the exact bytes an external signer must sign.
Parameters:
| Name | Type | Description |
|---|---|---|
document | Document | The document to prepare for signing. |
output_path | str | The path where the prepared PDF will be saved. |
options | DigitalSignatureOptions | The digital signature options, including the signing certificate. |
Returns: list - The bytes to be signed by the external signer.
sign
def sign(self, document: Document, output_path: str, options: DigitalSignatureOptions) -> NoneApplies an invisible digital signature to a document.
Parameters:
| Name | Type | Description |
|---|---|---|
document | Document | The document to sign. |
output_path | str | The path where the signed PDF will be saved. |
options | DigitalSignatureOptions | The digital signature options including certificate and metadata. |
sign_field
def sign_field(self, document: Document, output_path: str, field_name: str, options: DigitalSignatureOptions, appearance: SignatureAppearance) -> NoneApplies a signature to a document using an existing signature field. Supports both digital signatures (with certificate) and electronic signatures (visual only).
Parameters:
| Name | Type | Description |
|---|---|---|
document | Document | The document to sign. |
output_path | str | The path where the signed PDF will be saved. |
field_name | str | The name of the existing signature form field to use for the signature. |
options | DigitalSignatureOptions | The digital signature options. Can be null for electronic signatures. |
appearance | SignatureAppearance | The visual appearance of the signature. |