Syncfusion Essential PDF is aASP.NET Core PDF libraryused to create, read, and edit PDF documents. Using this library, you can apply one or more digital signature to a PDF document using C# and VB.NET. C# VB.NET C# VB.NET A complete working sample can be downloaded from DigitalSignatureSample.zip. By executing the program, you will get the PDF document as follows. Note: Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message. Conclusion Ihope you enjoyed learning about how toapply one or more digitalsignatures to a PDF in ASP.NET Core. Youcan refer to ourASP.NET Core PDFfeature tourpage toknow about its othergroundbreaking feature representationsanddocumentation,and how toquickly getstarted for configuration specifications. You can also explore ourASP.NET Core PDF exampleto understand how to createand manipulate data in the .NET PDF. Forcurrent customers,you can check out ourDocument processinglibrariesfrom theLicense and Downloadspage.If you arenew to Syncfusion, you can try our 30-dayfree trialto check out ourASP.NET Core PDF and other .NET Core controls. Ifyou have any queries or require clarifications, please let us know in thecomments section below.You can also contact us through oursupport forums,Direct-Trac,orfeedback portal.We are always happy to assist you!Steps to apply one or more digital signature to PDF document programmatically:
using Syncfusion.Pdf;using Syncfusion.Pdf.Parsing;using Syncfusion.Pdf.Security;using Syncfusion.Pdf.Graphics;
Imports Syncfusion.PdfImports Syncfusion.Pdf.ParsingImports Syncfusion.Pdf.SecurityImports Syncfusion.Pdf.Graphics
<h2>Click the button to generate PDF</h2>@using (Html.BeginForm("GeneratePDF", "Home", FormMethod.Post)){ <input type="submit" value="GeneratePDF" />}
//Load the PDF documentFileStream docStream = new FileStream("SignatureFields.pdf", FileMode.Open, FileAccess.Read);PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);//Gets the first page of the documentPdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;//Gets the first signature field of the PDF documentPdfLoadedSignatureField signatureField1 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;//Creates a certificateFileStream certificateStream1 = new FileStream("PDF.pfx", FileMode.Open, FileAccess.Read);PdfCertificate certificate1 = new PdfCertificate(certificateStream1, "syncfusion");signatureField1.Signature = new PdfSignature(loadedDocument, page, certificate1, "Signature", signatureField1);FileStream imageStream = new FileStream("Student Signature.jpg", FileMode.Open, FileAccess.Read);//Draw imagePdfBitmap signatureImage = new PdfBitmap(imageStream);signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, 90, 20);//Save the document into streamMemoryStream stream = new MemoryStream();loadedDocument.Save(stream);//Load the signed PDF documentPdfLoadedDocument signedDocument = new PdfLoadedDocument(stream);//Load the PDF pagePdfLoadedPage loadedPage = signedDocument.Pages[0] as PdfLoadedPage;//Gets the first signature field of the PDF documentPdfLoadedSignatureField signatureField2 = signedDocument.Form.Fields[1] as PdfLoadedSignatureField;signatureField2.Signature = new PdfSignature(signedDocument, loadedPage, certificate1, "Signature", signatureField2);FileStream imageStream1 = new FileStream("Teacher Signature.png", FileMode.Open, FileAccess.Read);PdfBitmap signatureImage1 = new PdfBitmap(imageStream1);//Draw imagesignatureField2.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage1, 0, 0, 90, 20);//Saving the PDF to the MemoryStreamMemoryStream signedStream = new MemoryStream();signedDocument.Save(signedStream);//Set the position as '0'.signedStream.Position = 0;//Download the PDF document in the browserFileStreamResult fileStreamResult = new FileStreamResult(signedStream, "application/pdf");fileStreamResult.FileDownloadName = "DigitalSignatureSample.pdf";return fileStreamResult;
'Load the PDF documentDim docStream As FileStream = New FileStream("SignatureFields.pdf", FileMode.Open, FileAccess.Read)Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument(docStream)'Gets the first page of the documentDim page As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage)'Gets the first page of the documentDim signatureField1 As PdfLoadedSignatureField = TryCast(loadedDocument.Form.Fields(0), PdfLoadedSignatureField)'Creates a certificateDim certificateStream1 As FileStream = New FileStream("PDF.pfx", FileMode.Open, FileAccess.Read)Dim certificate1 As PdfCertificate = New PdfCertificate(certificateStream1, "syncfusion")signatureField1.Signature = New PdfSignature(loadedDocument, page, certificate1, "Signature", signatureField1)Dim imageStream As FileStream = New FileStream("Student Signature.jpg", FileMode.Open, FileAccess.Read)'Draw imageDim signatureImage As PdfBitmap = New PdfBitmap(imageStream)signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, 90, 20)'Save the document into streamDim stream As MemoryStream = New MemoryStream()loadedDocument.Save(stream)'Load the signed PDF documentDim signedDocument As PdfLoadedDocument = New PdfLoadedDocument(stream)'Load the PDF pageDim loadedPage As PdfLoadedPage = TryCast(signedDocument.Pages(0), PdfLoadedPage)Dim signatureField2 As PdfLoadedSignatureField = TryCast(signedDocument.Form.Fields(1), PdfLoadedSignatureField)signatureField2.Signature = New PdfSignature(signedDocument, loadedPage, certificate1, "Signature", signatureField2)Dim imageStream1 As FileStream = New FileStream("Teacher Signature.png", FileMode.Open, FileAccess.Read)'Draw imageDim signatureImage1 As PdfBitmap = New PdfBitmap(imageStream1)signatureField2.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage1, 0, 0, 90, 20)'Saving the PDF to the MemoryStreamDim signedStream As MemoryStream = New MemoryStream()signedDocument.Save(signedStream)'Set the position as '0'.signedStream.Position = 0'Download the PDF document in the browserDim fileStreamResult As FileStreamResult = New FileStreamResult(signedStream, "application/pdf")fileStreamResult.FileDownloadName = "DigitalSignatureSample.pdf"Return fileStreamResult
See Also
Itextsharp In C#