|
| 1 | +# Add a digital signature in a Word document using C# |
| 2 | + |
| 3 | +The [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (DocIO) empowers you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **add an invisible digital signature to a Word document** using C#. |
| 4 | + |
| 5 | +## Steps to add an invisible digital signature to a Word document programmatically |
| 6 | + |
| 7 | +Step 1: Create a new .NET Core console application project. |
| 8 | + |
| 9 | +Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/). |
| 10 | + |
| 11 | +Step 3: Include the following namespaces in the Program.cs file. |
| 12 | + |
| 13 | +```csharp |
| 14 | +using Syncfusion.DocIO; |
| 15 | +using Syncfusion.DocIO.DLS; |
| 16 | +using Syncfusion.Office; |
| 17 | +``` |
| 18 | + |
| 19 | +Step 4: Add the following code snippet in Program.cs file to add an invisible digital signature to a Word document. |
| 20 | + |
| 21 | +```csharp |
| 22 | +//Opens an existing Word document. |
| 23 | +WordDocument document = new WordDocument(Path.GetFullPath(@"Data\Template.docx")); |
| 24 | +//Loads the signing certificate from disk. |
| 25 | +OfficeDigitalSignatureCertificate certificate = new OfficeDigitalSignatureCertificate(Path.GetFullPath(@"Data\certificate.pfx"), "password123"); |
| 26 | +//Configures signature settings. |
| 27 | +SignatureSettings settings = new SignatureSettings(); |
| 28 | +settings.Comments = "Approved"; |
| 29 | +settings.SignTime = DateTime.Now; |
| 30 | +//Sets the application version used to create the signature. |
| 31 | +settings.ApplicationVersion = "16.0"; |
| 32 | +//Sets the Office version recorded with the signature. |
| 33 | +settings.OfficeVersion = "16.0"; |
| 34 | +//Sets the Windows version recorded with the signature. |
| 35 | +settings.WindowsVersion = "10.0"; |
| 36 | +//Sets the horizontal resolution recorded with the signature. |
| 37 | +settings.HorizontalResolution = 1920; |
| 38 | +//Sets the vertical resolution recorded with the signature. |
| 39 | +settings.VerticalResolution = 1080; |
| 40 | +//Sets the color depth recorded with the signature. |
| 41 | +settings.ColorDepth = 32; |
| 42 | +//Sets the cryptographic provider identifier. |
| 43 | +settings.ProviderId = new Guid("00000000-0000-0000-0000-000000000000"); |
| 44 | +//Adds an invisible digital signature to the document using the certificate and settings. |
| 45 | +document.AddDigitalSignature(certificate, settings); |
| 46 | +//Saves the Word document to file. |
| 47 | +document.Save(Path.GetFullPath(@"Output\Result.docx"), FormatType.Docx); |
| 48 | +//Closes the document |
| 49 | +document.Close(); |
| 50 | +``` |
| 51 | + |
| 52 | +More information about add a digital signature in a Word document can be refer in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-digital-signature) section. |
0 commit comments