PdfSignature
16 Dec 20254 minutes to read
‘PdfSignature’ class represents a digital signature used for signing a PDF document.
// Load the document
let document: PdfDocument = new PdfDocument(data);
// Gets the first page of the document
let page: PdfPage = document.getPage(0);
// Access the PDF form
let form: PdfForm = document.form;
// Create a new signature field
let field: PdfSignatureField = new PdfSignatureField(page, 'Signature', {x: 10, y: 10, width: 100, height: 50});
// Create a new signature using PFX data and private key
const sign: PdfSignature = PdfSignature.create({ cryptographicStandard: CryptographicStandard.cms, digestAlgorithm: DigestAlgorithm.sha256 }, certData, password);
// Sets the signature to the field
field.setSignature(sign);
// Add the field into PDF form
form.add(field);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Methods
getCertificateInformation
Gets the certificate information associated with the PDF signature.
Returns PdfCertificateInformation
getSignatureOptions
Gets the options for configuring a digital signature in a PDF document.
Returns PdfSignatureOptions
getSignedDate
Gets the date when the PDF was signed.
Returns Date
create
Creates a new PDF signature using a callback function for external signing.
| Parameter | Type | Description |
|---|---|---|
| callBack | ExternalSignatureCallback |
A callback function that computes the signed document hash for external signature. |
| options | PdfSignatureOptions |
Configuration options for the signature. |
Returns PdfSignature
create
Creates a new PDF signature using a callback function for external signing.
| Parameter | Type | Description |
|---|---|---|
| callBack | ExternalSignatureCallback |
A callback function that computes the signed document hash for external signature. |
| publicCertificates | Uint8Array[] |
An array of public certificates. |
| options | PdfSignatureOptions |
Configuration options for the signature. |
Returns PdfSignature
create
Creates a new PDF signature using PFX certificate data and a password.
| Parameter | Type | Description |
|---|---|---|
| pfxData |
Uint8Array | string
|
The PFX certificate data. |
| password | string |
The password for the certificate. |
| options | PdfSignatureOptions |
Configuration options for the signature. |
Returns PdfSignature
replaceEmptySignature
Replaces an empty signature field in a PDF document with externally signed data.
| Parameter | Type | Description |
|---|---|---|
| inputPdfData | Uint8Array |
The PDF document data. |
| signatureName | string |
The name of the signature field to replace. |
| signedData | Uint8Array |
The externally signed content to embed. |
| algorithm | DigestAlgorithm |
The digest algorithm used to hash the PDF content. |
| publicCertificates | Uint8Array[] |
Optional array of public certificate data used for signing. |
| options (optional) | Object |
Configuration options for signature replacement. |
Returns Uint8Array
replaceEmptySignature
Replaces an empty signature field in a PDF document with externally signed data.
Returns void