Sign with Digital Signature
Use the Wordize Signature for .NET module to work with the digital signature in the document.
Please note that Wordize Signature for .NET currently only supports DOC, DOT, DOCX, DOTX, DOCM, ODT, OTT, and XPS formats. Select document conversion modules to work with the required formats.
Wordize allows users to digitally sign documents, ensuring their authenticity and integrity. A digital signature verifies that the document has not been altered after signing and confirms the signer’s identity. This feature is essential for legal documents, contracts, and other sensitive files.
With Wordize Signature for .NET, you can:
- Sign documents programmatically
- Remove signatures when needed
- Work with cryptographic standards for secure signing
Sign a Document
To sign a document with a digital signature, use the Sign method and the CertificateHolder digital certificate.
CertificateHolder is a digital certificate that follows the internationally accepted X.509 PKI standard, ensuring the public key within the certificate is linked to the signer included inside the certificate.
A common scenario for signing a document is when the input document format matches the output document format. In such a scenario, there is no need to parse the document.
Wordize allows you to sign a document without loading the document into the internal Document Object Model in the following formats: Doc, Dot, Docx, Dotx, Docm, Dotm, Odt, Ott, Xps, and OpenXps. The Signer class provides a convenient way to perform this type of signing.
The following code example shows how to add a digital signature to a document:
CertificateHolder holder = CertificateHolder.Create("morzal.pfx", "wordize");
Signer.Sign("Document.docx", "SignedDocument.1.docx", holder);
Find a full list of code examples for sign a document in the Sign a Document Code Examples section at the bottom of the page.
Sign a Document Using Sign Options
In addition to the X.509 digital certificate, you can specify the document signing options using the following properties of the SignOptions class:
- Comments – to add a comment to your sign
- SignTime – to add the date of signing
- DecryptionPassword – to add a password to decrypt the source document
- ProviderId – to specify the signature provider class ID
- XmlDsigLevel – to specify the digital signature level based on the XML-DSig standard
The following code example shows how to digitally sign a document, specifying sign options:
SignOptions signOptions = new SignOptions();
signOptions.Comments = "My Signature";
signOptions.SignTime = DateTime.Now;
CertificateHolder holder = CertificateHolder.Create("morzal.pfx", "wordize");
Signer.Sign("Document.docx", "SignedDocument.3.docx", holder, signOptions);
Find a full list of code examples for sign a document using sign options in the Sign a Document Code Examples section at the bottom of the page.
Remove a Digital Signature
If you need to remove digital signatures from a document, use the RemoveAllSignatures methods:
Signer.RemoveAllSignatures("SignedDocument.docx", "UnsignedDocument.docx");
Find a full list of code examples for remove a digital signature in the following Sign a Document Code Examples section.
Sign a Document Code Examples
Wordize provides both a Standard API and a Fluent API, allowing developers to choose the most convenient approach for their needs.
Wordize API
Sign a Document
method Sign(string, string, CertificateHolder)
CertificateHolder holder = CertificateHolder.Create("morzal.pfx", "wordize");
Signer.Sign("Document.docx", "SignedDocument.1.docx", holder);
method Sign(Stream, Stream, CertificateHolder)
CertificateHolder holder = CertificateHolder.Create("morzal.pfx", "wordize");
using var streamIn = File.OpenRead("Document.docx");
using var streamOut = File.Create("SignedDocument.2.docx");
Signer.Sign(streamIn, streamOut, holder);
Sign a Document Using Sign Options
method Sign(string, string, CertificateHolder, SignOptions)
SignOptions signOptions = new SignOptions();
signOptions.Comments = "My Signature";
signOptions.SignTime = DateTime.Now;
CertificateHolder holder = CertificateHolder.Create("morzal.pfx", "wordize");
Signer.Sign("Document.docx", "SignedDocument.3.docx", holder, signOptions);
method Sign(Stream, Stream, CertificateHolder, SignOptions)
SignOptions signOptions = new SignOptions();
signOptions.Comments = "My Signature";
signOptions.SignTime = DateTime.Now;
CertificateHolder holder = CertificateHolder.Create("morzal.pfx", "wordize");
using var streamIn = File.OpenRead("Document.docx");
using var streamOut = File.Create("SignedDocument.4.docx");
Signer.Sign(streamIn, streamOut, holder);
Remove a Digital Signature
method RemoveAllSignatures(string, string)
Signer.RemoveAllSignatures("SignedDocument.docx", "UnsignedDocument.docx");
method RemoveAllSignatures(Stream, Stream)
using var streamIn = File.OpenRead("SignedDocument.docx");
using var streamOut = File.Create("UnsignedDocument.docx");
Signer.RemoveAllSignatures(streamIn, streamOut);
Wordize Fluent API
Within the Fluent API, there is a context. SignerContext allows you to customize the signing document process. You can split documents with or without context.
Sign a Document
method to Sign a document form a file and save the result to a file
SignerContext signerContext = new SignerContext();
signerContext.CertificateHolder = CertificateHolder.Create("morzal.pfx", "wordize");
signerContext.SignOptions = new SignOptions();
Signer.Create(signerContext)
.From("DocumentIn.docx")
.To("DocumentOut.docx")
.Execute();
method to Sign a document form a file and save the result to a stream
SignerContext signerContext = new SignerContext();
signerContext.CertificateHolder = CertificateHolder.Create("morzal.pfx", "wordize");
signerContext.SignOptions = new SignOptions();
using var streamOut = File.Create("SignedDocument.5.docx");
Signer.Create(signerContext)
.From("DocumentIn.docx")
.To(streamOut)
.Execute();
Sign a Document Using Sign Options
method to Sign a document
SignerContext signerContext = new SignerContext();
signerContext.CertificateHolder = CertificateHolder.Create("morzal.pfx", "wordize");
signerContext.SignOptions = new SignOptions();
signerContext.SignOptions.Comments = "My Signature";
signerContext.SignOptions.SignTime = DateTime.Now;
Signer.Create(signerContext)
.From("DocumentIn.docx")
.To("DocumentOut.docx")
.Execute();
method to Sign a document, filled in with some data
Another scenario involves signing the resulting document, for example, after filling a template with data. In this case, signature details can be specified in the appropriate save options.
DocSaveOptions docSaveOptions = new DocSaveOptions();
docSaveOptions.DigitalSignatureDetails =
new DigitalSignatureDetails(CertificateHolder.Create("morzal.pfx", "wordize"), new SignOptions() { Comments = "My Signature" });
Converter.Create()
.From("DocumentIn.docx")
.To("DocumentOut.doc", docSaveOptions)
.Execute();
Wordize also supports signing PDF documents in this scenario.
method to Sign a PDF document
The following code example shows how to convert DOCX to PDF and sign the output PDF.
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.DigitalSignatureDetails =
new PdfDigitalSignatureDetails(CertificateHolder.Create("morzal.pfx", "wordize"), "Signing Reason", "Signing Location", DateTime.Now);
Converter.Create()
.From("DocumentIn.docx")
.To("DocumentOut.pdf", pdfSaveOptions)
.Execute();
With this approach, the output of any processor can be signed if saved in the following formats:
- DOC or DOT by specifying DocSaveOptions.DigitalSignatureDetails
- DOCX, DOTX, DOCM, or DOTM by specifying OoxmlSaveOptions.DigitalSignatureDetails
- ODT or OTT by specifying OdtSaveOptions.DigitalSignatureDetails
- XPS or OpenXPS by specifying XpsSaveOptions.DigitalSignatureDetails
- PDF by specifying PdfSaveOptions.DigitalSignatureDetails
Note: If the input and output file formats passed to Signer do not match, and the output file format supports signing, the signing process is performed similarly to conversion by specifying DigitalSignatureDetails in the appropriate SaveOptions.