How to apply one or more digital signatures to a PDF? | Syncfusion (2024)

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.

Steps to apply one or more digital signature to PDF document programmatically:

  1. Create a new C# ASP.NET Core Web application project. How to apply one or more digital signatures to a PDF? | Syncfusion (1)
  2. Select Web application pattern (Model-View-Controller) for the project. How to apply one or more digital signatures to a PDF? | Syncfusion (2)
  3. Install the Syncfusion.Pdf.Net.Core NuGet package as reference to your .NET Standard application from NuGet.org. How to apply one or more digital signatures to a PDF? | Syncfusion (3)
  4. A default controller with name HomeController.cs gets added on creation of ASP.NET Core project. Include the following namespaces in that HomeController.cs file.

C#

using Syncfusion.Pdf;using Syncfusion.Pdf.Parsing;using Syncfusion.Pdf.Security;using Syncfusion.Pdf.Graphics;

VB.NET

Imports Syncfusion.PdfImports Syncfusion.Pdf.ParsingImports Syncfusion.Pdf.SecurityImports Syncfusion.Pdf.Graphics
  1. A default action method named Index will be present in HomeController.cs. Right-click the Index method and selectGo To Viewwhere you will be directed to its associated view pageIndex.cshtml.
  2. Add a new button in theIndex.cshtmlas follows.
    <h2>Click the button to generate PDF</h2>@using (Html.BeginForm("GeneratePDF", "Home", FormMethod.Post)){ <input type="submit" value="GeneratePDF" />}
  1. Add a new action methodGeneratePDF inHomeController.csand include the following code snippetto create a PDF file and download it.

C#

//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;

VB.NET

'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

A complete working sample can be downloaded from DigitalSignatureSample.zip.

By executing the program, you will get the PDF document as follows. How to apply one or more digital signatures to a PDF? | Syncfusion (4)

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!

How to apply one or more digital signatures to a PDF? | Syncfusion (2024)
Top Articles
9 Hairfall Tips in Astrology
Republic World
Nullreferenceexception 7 Days To Die
Skyward Sinton
Google Sites Classroom 6X
Pollen Count Central Islip
Blue Ridge Now Mugshots Hendersonville Nc
ExploreLearning on LinkedIn: This month&#39;s featured product is our ExploreLearning Gizmos Pen Pack, the…
Lonadine
Les Rainwater Auto Sales
Carolina Aguilar Facebook
Sam's Club La Habra Gas Prices
Bj Alex Mangabuddy
Paychex Pricing And Fees (2024 Guide)
Illinois VIN Check and Lookup
Axe Throwing Milford Nh
Daytonaskipthegames
R&S Auto Lockridge Iowa
Dr. Nicole Arcy Dvm Married To Husband
Orange Park Dog Racing Results
HP PARTSURFER - spare part search portal
Jail Roster Independence Ks
Airg Com Chat
Pipa Mountain Hot Pot渝味晓宇重庆老火锅 Menu
The Bold and the Beautiful
The Rise of "t33n leaks": Understanding the Impact and Implications - The Digital Weekly
R3Vlimited Forum
Rund um die SIM-Karte | ALDI TALK
Craigslist Free Stuff San Gabriel Valley
Fandango Pocatello
UPS Drop Off Location Finder
Desirulez.tv
A Man Called Otto Showtimes Near Carolina Mall Cinema
Indiana Immediate Care.webpay.md
Closest 24 Hour Walmart
Google Jobs Denver
Colorado Parks And Wildlife Reissue List
Ny Post Front Page Cover Today
Umiami Sorority Rankings
Hingham Police Scanner Wicked Local
Registrar Lls
Stewartville Star Obituaries
Skyward Marshfield
Atom Tickets – Buy Movie Tickets, Invite Friends, Skip Lines
Yakini Q Sj Photos
Florida Lottery Powerball Double Play
Definition of WMT
Elvis Costello announces King Of America & Other Realms
786 Area Code -Get a Local Phone Number For Miami, Florida
Denys Davydov - Wikitia
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 6203

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.