How to add multiple digital signature ?
The Syncfusion Essential® PDF is a comprehensive, high-performance .NET PDF library that enables you to create, read, and edit PDF documents. Using this library, you can efficiently add multiple digital signatures to a PDF document, ensuring that each signature is properly authenticated and the document remains secure.
Steps to add multiple digital signatures in a PDF document programmatically
- Create a new console application project.
- Install the Syncfusion.Pdf.Net.Core NuGet package as a reference in your console application from NuGet.org.
- Include the following namespaces in the Program.cs file.
C#
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
using Syncfusion.Pdf;
- Use the following code sample in Program.cs to add multiple digital signatures in a PDF document.
C#
// Load the PDF document.
FileStream docStream = new FileStream("SignatureFields.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
// Get the first page of the document.
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
// Get the first signature field of the PDF document.
PdfLoadedSignatureField signatureField1 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
// Create a certificate.
FileStream certificateStream1 = new FileStream("PDF.pfx", FileMode.Open, FileAccess.Read);
PdfCertificate certificate1 = new PdfCertificate(certificateStream1, "password123");
// Add signature to the signature field.
signatureField1.Signature = new PdfSignature(loadedDocument, page, certificate1, "Signature", signatureField1);
// Get the image as a stream.
FileStream imageStream = new FileStream("Student Signature.jpg", FileMode.Open, FileAccess.Read);
PdfBitmap signatureImage = new PdfBitmap(imageStream);
// Draw an image in signature appearance.
signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, 90, 20);
// Save the document into the stream.
MemoryStream stream = new MemoryStream();
loadedDocument.Save(stream);
// Load the signed PDF document.
PdfLoadedDocument signedDocument = new PdfLoadedDocument(stream);
// Load the PDF page.
PdfLoadedPage loadedPage = signedDocument.Pages[0] as PdfLoadedPage;
// Get the first signature field of the PDF document.
PdfLoadedSignatureField signatureField2 = signedDocument.Form.Fields[1] as PdfLoadedSignatureField;
// Add the signature to the signature field.
signatureField1.Signature = new PdfSignature(signedDocument, loadedPage, certificate1, "Signature", signatureField2);
// Load the image as a stream.
FileStream imageStream1 = new FileStream("Teacher Signature.png", FileMode.Open, FileAccess.Read);
PdfBitmap signatureImage1 = new PdfBitmap(imageStream1);
// Draw the image in signature appearance.
signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage1, 0, 0, 90, 20);
// Create a file stream to save the PDF document to a file in the specified output path.
using (FileStream stream = new FileStream("Output.pdf", FileMode.Create, FileAccess.Write))
{
// Save the PDF document to the file stream.
signedDocument.Save(stream);
}
// Close the document and release resources.
signedDocument.Close(true);
By executing the program, you will generate the following PDF document.
Take a moment to peruse the documentation to learn how to add digital signatures in a PDF document.
Conclusion
I hope you enjoyed learning how to add multiple digital signatures to a PDF document.
You can refer to our ASP.NET Core PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our ASP.NET Core PDF examples to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!