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.
using Nutrient;Construction
public Signature()Methods
AddDocumentTimestamp
public void AddDocumentTimestamp(Document document, string outputPath, TimestampConfiguration timestamp)Appends a document timestamp to a document, protecting its current state and its validation material.
Parameters
| Name | Type | Description |
|---|---|---|
document | Document | The document to timestamp. |
outputPath | string | The path where the updated PDF will be saved. |
timestamp | TimestampConfiguration | The timestamp authority configuration. |
public void AddDocumentTimestamp(Document document, Stream output, TimestampConfiguration timestamp)Appends a document timestamp to a document, writing the result to a stream.
Parameters
| Name | Type | Description |
|---|---|---|
document | Document | The document to timestamp. |
output | Stream | The output stream where the updated PDF will be written. |
timestamp | TimestampConfiguration | The timestamp authority configuration. |
AddLtvInformation
public void AddLtvInformation(Document document, string outputPath)Adds 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. |
outputPath | string | The path where the updated PDF will be saved. |
public void AddLtvInformation(Document document, Stream output)Adds long-term validation material for all signed signatures, writing the result to a stream.
Parameters
| Name | Type | Description |
|---|---|---|
document | Document | The signed document to add validation material to. |
output | Stream | The output stream where the updated PDF will be written. |
FinishSignature
public void FinishSignature(Document preparedDocument, string outputPath, Byte[] signedData, DigitalSignatureOptions options)Completes external signing (phase two) with a raw signature value produced by an external signer.
Parameters
| Name | Type | Description |
|---|---|---|
preparedDocument | Document | The prepared document returned by PrepareSignature. |
outputPath | string | The path where the signed PDF will be saved. |
signedData | Byte[] | The raw signature value over the prepared bytes. |
options | DigitalSignatureOptions | The digital signature options with the same certificate used to prepare. |
public void FinishSignature(Document preparedDocument, Stream output, Byte[] signedData, DigitalSignatureOptions options)Completes external signing (phase two) with a raw signature value, writing the result to a stream.
Parameters
| Name | Type | Description |
|---|---|---|
preparedDocument | Document | The prepared document. |
output | Stream | The output stream where the signed PDF will be written. |
signedData | Byte[] | The raw signature value over the prepared bytes. |
options | DigitalSignatureOptions | The digital signature options with the same certificate used to prepare. |
FinishSignatureWithCms
public void FinishSignatureWithCms(Document preparedDocument, string outputPath, Byte[] signatureContainer)Completes external signing (phase two) with a complete signature container produced by an external signing service.
Parameters
| Name | Type | Description |
|---|---|---|
preparedDocument | Document | The prepared document. |
outputPath | string | The path where the signed PDF will be saved. |
signatureContainer | Byte[] | The complete, DER-encoded CMS signature container. |
public void FinishSignatureWithCms(Document preparedDocument, Stream output, Byte[] signatureContainer)Completes external signing (phase two) with a complete signature container, writing the result to a stream.
Parameters
| Name | Type | Description |
|---|---|---|
preparedDocument | Document | The prepared document. |
output | Stream | The output stream where the signed PDF will be written. |
signatureContainer | Byte[] | The complete, DER-encoded CMS signature container. |
PrepareSignature
public Byte[] PrepareSignature(Document document, string outputPath, DigitalSignatureOptions options)Starts 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. |
outputPath | string | The path where the prepared PDF will be saved. |
options | DigitalSignatureOptions | The digital signature options, including the signing certificate. |
Returns: Byte[] - The bytes to be signed by the external signer.
public Byte[] PrepareSignature(Document document, Stream output, DigitalSignatureOptions options)Starts external signing (phase one), writing the prepared PDF to a stream and returning the bytes an external signer must sign.
Parameters
| Name | Type | Description |
|---|---|---|
document | Document | The document to prepare for signing. |
output | Stream | The output stream where the prepared PDF will be written. |
options | DigitalSignatureOptions | The digital signature options, including the signing certificate. |
Returns: Byte[] - The bytes to be signed by the external signer.
Sign
public void Sign(Document document, string outputPath, DigitalSignatureOptions options)Applies an invisible digital signature to a document.
Parameters
| Name | Type | Description |
|---|---|---|
document | Document | The document to sign. |
outputPath | string | The path where the signed PDF will be saved. |
options | DigitalSignatureOptions | The digital signature options including certificate and metadata. |
public void Sign(Document document, Stream output, DigitalSignatureOptions options)Applies an invisible digital signature to a document, writing the result to a stream.
Parameters
| Name | Type | Description |
|---|---|---|
document | Document | The document to sign. |
output | Stream | The output stream where the signed PDF will be written. |
options | DigitalSignatureOptions | The digital signature options including certificate and metadata. |
SignField
public void SignField(Document document, string outputPath, string fieldName, DigitalSignatureOptions? options, SignatureAppearance? appearance)Applies 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. |
outputPath | string | The path where the signed PDF will be saved. |
fieldName | string | 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. |
public void SignField(Document document, Stream output, string fieldName, DigitalSignatureOptions? options, SignatureAppearance? appearance)Applies a signature to a document using an existing signature field, writing the result to a stream. Supports both digital signatures (with certificate) and electronic signatures (visual only).
Parameters
| Name | Type | Description |
|---|---|---|
document | Document | The document to sign. |
output | Stream | The output stream where the signed PDF will be written. |
fieldName | string | 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. |
Resource management
public void Dispose()Signature implements IDisposable and owns native resources. Always call Dispose() or use a C# using declaration: it is not released automatically.