Saturday, October 30, 2021

Create Digital Signature in PDF in C#/VB.NET

 Digital signature is the alternative way of signing documents in era of electronic exchange of documents. Creating digital signature in PDF, without any doubt, becomes one of the most popular ways to protect PDF file from editing and tampering. This section will introduce a solution to create digital signature in PDF via a .NET PDF component.

Spire.PDF for .NET, with rich features to protect and manipulate PDF documents, allows you to keep your PDF secure by creating digital signature in PDF with C#, VB.NET. As long as the digital signature is signed, the signer's identity has been verified and your PDF document can be safe and cannot be modified.

Please download Spire.PDF for .NET and view the screenshot of this task as below picture:

Create Digital Signature

In the key code, first you are required to create one instance of Spire.Pdf.Security.PdfCertificate class with two parameters passed: a certificate file and the file password. This instance is named to be digi. After that, digi is used as a parameter of another instance in a different class: PdfSignature class. Here it is called signature. In order to sign PDF digital signature in any page, a "page" parameter is provided. Through DocumentPermission, you can restrict the PDF permission to be AllowComments, AllowFormFill and ForbidChanges.

[C#]
using Spire.Pdf;
using Spire.Pdf.Security;

namespace CreateDigitalSignature
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument("Sample.pdf");
            PdfPageBase page = doc.Pages[0];

            PdfCertificate cert = new PdfCertificate("Demo.pfx", "e-iceblue");

            PdfSignature signature = new PdfSignature(doc, page, cert, "demo");

            signature.ContactInfo = "Harry";
            signature.Certificated = true;

            signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;

            doc.SaveToFile("Result.pdf");
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Security

Namespace CreateDigitalSignature
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As PdfDocument = New PdfDocument("Sample.pdf")
    Dim page As PdfPageBase = doc.Pages(0)
    Dim cert As PdfCertificate = New PdfCertificate("Demo.pfx", "e-iceblue")
    Dim signature As PdfSignature = New PdfSignature(doc, page, cert, "demo")
    signature.ContactInfo = "Harry"
    signature.Certificated = True
    signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill
    doc.SaveToFile("Result.pdf")
		End Sub
	End Class
End Namespace

Spire.PDF for .NET is a .NET PDF component which can secure your PDF by encrypting PDF and creating PDF digital signature. When you need to unlock PDF file, it also enables you to decrypt PDF in a fast way.

No comments:

Post a Comment

No String Argument Constructor/Factory Method to Deserialize From String Value

  In this short article, we will cover in-depth the   JsonMappingException: no String-argument constructor/factory method to deserialize fro...