Skip to content

Commit 144828c

Browse files
Update Program.cs
1 parent 28372ee commit 144828c

1 file changed

Lines changed: 39 additions & 23 deletions

File tree

  • Digital Signature/Multiple-digital-signature/.NET/Multiple-digital-signature

Digital Signature/Multiple-digital-signature/.NET/Multiple-digital-signature/Program.cs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,59 @@
33
using Syncfusion.Pdf.Security;
44
using Syncfusion.Pdf;
55

6-
//Load an existing PDF document.
6+
// Open the existing PDF document.
77
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/SignatureFields.pdf"));
8-
//Get the first page of the document.
8+
9+
// Retrieve the first page from the PDF document.
910
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
10-
//Get the first signature field of the PDF document.
11+
12+
// Access the first signature field available in the PDF form.
1113
PdfLoadedSignatureField signatureField1 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
12-
//Create a certificate instance from a PFX file with a private key.
14+
15+
// Create a certificate object using the PFX file and its password.
1316
PdfCertificate certificate1 = new PdfCertificate(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion");
14-
//Add a signature to the signature field.
15-
signatureField1.Signature = new PdfSignature(loadedDocument, page, certificate1, "Signature", signatureField1);
16-
//Set an image for the signature field.
17+
18+
// Digitally sign the first signature field.
19+
signatureField1.Signature = new PdfSignature(loadedDocument, page, certificate1, "Signature1", signatureField1);
20+
21+
// Load the signature image for the first signer.
1722
FileStream imageStream1 = new FileStream(Path.GetFullPath(@"Data/Student Signature.jpg"), FileMode.Open, FileAccess.Read);
23+
1824
PdfBitmap signatureImage = new PdfBitmap(imageStream1);
19-
imageStream1.Position = 0;
20-
//Insert an image in the signature appearance.
25+
26+
27+
// Render the signature image within the signature field appearance.
2128
signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, signatureField1.Bounds.Width, signatureField1.Bounds.Height);
22-
//Save the document into the stream.
29+
30+
// Save the signed PDF into a memory stream.
2331
MemoryStream stream = new MemoryStream();
2432
loadedDocument.Save(stream);
25-
//Close the PDF document
33+
34+
// Close the original PDF document instance.
2635
loadedDocument.Close(true);
27-
stream.Position = 0;
28-
//Load the signed PDF document.
36+
37+
// Reopen the partially signed PDF from the memory stream.
2938
PdfLoadedDocument signedDocument = new PdfLoadedDocument(stream);
30-
//Load the PDF page.
39+
40+
// Retrieve the first page of the signed document.
3141
PdfLoadedPage loadedPage = signedDocument.Pages[0] as PdfLoadedPage;
32-
//Get the first signature field of the PDF document.
42+
43+
// Access the second signature field in the PDF form.
3344
PdfLoadedSignatureField signatureField2 = signedDocument.Form.Fields[1] as PdfLoadedSignatureField;
34-
//Add a signature to the signature field.
35-
signatureField2.Signature = new PdfSignature(signedDocument, loadedPage, certificate1, "Signature", signatureField2);
36-
//Set an image for the signature field.
45+
46+
// Apply a digital signature to the second signature field.
47+
signatureField2.Signature = new PdfSignature(signedDocument, loadedPage, certificate1, "Signature2", signatureField2);
48+
49+
// Load the signature image for the second signer.
3750
FileStream imageStream2 = new FileStream(Path.GetFullPath(@"Data/Teacher Signature.png"), FileMode.Open, FileAccess.Read);
51+
3852
PdfBitmap signatureImage1 = new PdfBitmap(imageStream2);
39-
imageStream2.Position = 0;
40-
//Draw an image in the signature appearance.
53+
54+
// Display the signature image in the second signature field appearance.
4155
signatureField2.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage1, 0, 0, signatureField2.Bounds.Width, signatureField2.Bounds.Height);
42-
//Save the PDF document
56+
57+
// Save the fully signed PDF document.
4358
signedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
44-
//Close the PDF document
45-
signedDocument.Close(true);
59+
60+
// Close the signed PDF document.
61+
signedDocument.Close(true);

0 commit comments

Comments
 (0)