Skip to content

Commit b06d525

Browse files
committed
986143: Updated the SignedName details also in the Signature information in Digital Signature
1 parent ecd565d commit b06d525

File tree

7 files changed

+180
-222
lines changed
  • Digital Signature
    • Add-a-digital-signature-to-an-existing-document/.NET/Add-a-digital-signature-to-an-existing-document
    • Add-a-digital-signature-to-the-PDF-document/.NET/Add-a-digital-signature-to-the-PDF-document
    • Add-digital-signature-using-X509Certificate2/.NET/Add-digital-signature-using-X509Certificate2
    • Add-digital-signature-with-digest-algorithm/.NET/Add-digital-signature-with-digest-algorithm
    • Adding-a-digital-signature-with-CAdES-format/.NET/Adding-a-digital-signature-with-CAdES-format
    • Adding-a-signature-validation-appearance-in-a-PDF/.NET/Adding-a-signature-validation-appearance-in-a-PDF
    • Adding-a-timestamp-in-digital-signature-of-PDF/.NET/Adding-a-timestamp-in-digital-signature-of-PDF

7 files changed

+180
-222
lines changed
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
using Syncfusion.Drawing;
1+
using Syncfusion.Drawing;
42
using Syncfusion.Pdf;
53
using Syncfusion.Pdf.Graphics;
64
using Syncfusion.Pdf.Interactive;
75
using Syncfusion.Pdf.Parsing;
86
using Syncfusion.Pdf.Security;
97

10-
//Open existing PDF document as stream
11-
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read))
8+
//Open existing PDF document
9+
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"Data/Input.pdf"))
1210
{
13-
// Load the existing PDF document
14-
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream);
15-
1611
// Gets the first page of the document
1712
PdfPageBase page = loadedDocument.Pages[0];
1813

@@ -25,6 +20,7 @@
2520

2621
// Set signature information
2722
signature.Bounds = new RectangleF(227.6355f, 675.795044f, 150.57901f, 32.58f);
23+
signature.SignedName = "Syncfusion";
2824
signature.ContactInfo = "[email protected]";
2925
signature.LocationInfo = "Honolulu, Hawaii";
3026
signature.Reason = "I am the author of this document.";
@@ -36,14 +32,8 @@
3632
// Draw the image on the signature field
3733
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0, 0, signature.Bounds.Width, signature.Bounds.Height));
3834

39-
// Save the document to a file stream
40-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
41-
{
42-
loadedDocument.Save(outputFileStream);
43-
}
44-
45-
//Close the document.
46-
loadedDocument.Close(true);
35+
// Save the PDF document
36+
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
4737
certificateStream.Dispose();
4838
imageStream.Dispose();
4939
}
Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
using Syncfusion.Drawing;
1+
using Syncfusion.Drawing;
42
using Syncfusion.Pdf;
53
using Syncfusion.Pdf.Graphics;
64
using Syncfusion.Pdf.Security;
75

86
//Creates a new PDF document.
9-
PdfDocument document = new PdfDocument();
10-
11-
//Adds a new page.
12-
PdfPageBase page = document.Pages.Add();
7+
using (PdfDocument document = new PdfDocument())
8+
{
9+
//Adds a new page.
10+
PdfPageBase page = document.Pages.Add();
1311

14-
//Create graphics for the page.
15-
PdfGraphics graphics = page.Graphics;
12+
//Create graphics for the page.
13+
PdfGraphics graphics = page.Graphics;
1614

17-
//Creates a certificate instance from PFX file with private key.
18-
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
19-
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
15+
//Creates a certificate instance from PFX file with private key.
16+
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
17+
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
2018

21-
//Creates a digital signature.
22-
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
19+
//Creates a digital signature.
20+
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
2321

24-
//Sets an image for signature field.
25-
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
22+
//Sets an image for signature field.
23+
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
2624

27-
//Sets an image for signature field.
28-
PdfBitmap signatureImage = new PdfBitmap(imageStream);
25+
//Sets an image for signature field.
26+
PdfBitmap signatureImage = new PdfBitmap(imageStream);
2927

30-
//Sets signature information.
31-
signature.Bounds = new RectangleF(new PointF(0, 0), new SizeF(100,100));
32-
signature.ContactInfo = "[email protected]";
33-
signature.LocationInfo = "Honolulu, Hawaii";
34-
signature.Reason = "I am author of this document.";
28+
//Sets signature information.
29+
signature.Bounds = new RectangleF(new PointF(0, 0), new SizeF(100, 100));
30+
signature.SignedName = "Syncfusion";
31+
signature.ContactInfo = "[email protected]";
32+
signature.LocationInfo = "Honolulu, Hawaii";
33+
signature.Reason = "I am author of this document.";
3534

36-
//Draw the image in signature appearance.
37-
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0,0,100,100));
35+
//Draw the image in signature appearance.
36+
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, new RectangleF(0, 0, 100, 100));
3837

39-
//Create file stream.
40-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
41-
{
42-
//Save the PDF document to file stream.
43-
document.Save(outputFileStream);
44-
}
38+
//Save the PDF document
39+
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
4540

46-
//Close the document.
47-
document.Close(true);
41+
}
Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,41 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
using Syncfusion.Drawing;
1+
using Syncfusion.Drawing;
42
using Syncfusion.Pdf;
53
using Syncfusion.Pdf.Graphics;
64
using Syncfusion.Pdf.Security;
75
using System.Security.Cryptography.X509Certificates;
86

97
//Creates a new PDF document.
10-
PdfDocument document = new PdfDocument();
8+
using (PdfDocument document = new PdfDocument())
9+
{
1110

12-
//Adds a new page.
13-
PdfPage page = document.Pages.Add();
11+
//Adds a new page.
12+
PdfPage page = document.Pages.Add();
1413

15-
//Create graphics for the page.
16-
PdfGraphics graphics = page.Graphics;
14+
//Create graphics for the page.
15+
PdfGraphics graphics = page.Graphics;
1716

18-
//Creates a certificate instance from PFX file with private key.
19-
X509Certificate2 certificate = new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion");
20-
PdfCertificate pdfCertificate = new PdfCertificate(certificate);
17+
//Creates a certificate instance from PFX file with private key.
18+
X509Certificate2 certificate = new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "syncfusion");
19+
PdfCertificate pdfCertificate = new PdfCertificate(certificate);
2120

22-
//Creates a digital signature.
23-
PdfSignature signature = new PdfSignature(document, page, pdfCertificate, "Signature");
21+
//Creates a digital signature.
22+
PdfSignature signature = new PdfSignature(document, page, pdfCertificate, "Signature");
2423

25-
//Sets an image for signature field.
26-
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
27-
PdfBitmap signatureImage = new PdfBitmap(imageStream);
24+
//Sets an image for signature field.
25+
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
26+
PdfBitmap signatureImage = new PdfBitmap(imageStream);
2827

29-
//Sets signature information.
30-
signature.Bounds = new RectangleF(new PointF(0, 0), signatureImage.PhysicalDimension);
31-
signature.ContactInfo = "[email protected]";
32-
signature.LocationInfo = "Honolulu, Hawaii";
33-
signature.Reason = "I am author of this document.";
28+
//Sets signature information.
29+
signature.Bounds = new RectangleF(new PointF(0, 0), signatureImage.PhysicalDimension);
30+
signature.SignedName = "Syncfusion";
31+
signature.ContactInfo = "[email protected]";
32+
signature.LocationInfo = "Honolulu, Hawaii";
33+
signature.Reason = "I am author of this document.";
3434

35-
//Draws the signature image.
36-
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0);
35+
//Draws the signature image.
36+
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0);
3737

38-
//Create file stream.
39-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
40-
{
41-
//Save the PDF document to file stream.
42-
document.Save(outputFileStream);
43-
}
38+
// Save the PDF document
39+
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
4440

45-
//Close the document.
46-
document.Close(true);
41+
}
Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
using Syncfusion.Drawing;
1+
using Syncfusion.Drawing;
42
using Syncfusion.Pdf;
53
using Syncfusion.Pdf.Graphics;
64
using Syncfusion.Pdf.Security;
75

86
//Creates a new PDF document.
9-
PdfDocument document = new PdfDocument();
7+
using (PdfDocument document = new PdfDocument())
8+
{
109

11-
//Adds a new page.
12-
PdfPageBase page = document.Pages.Add();
10+
//Adds a new page.
11+
PdfPageBase page = document.Pages.Add();
1312

14-
//Create graphics with the page.
15-
PdfGraphics graphics = page.Graphics;
13+
//Create graphics with the page.
14+
PdfGraphics graphics = page.Graphics;
1615

17-
//Creates a certificate instance from PFX file with private key.
18-
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
19-
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
16+
//Creates a certificate instance from PFX file with private key.
17+
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
18+
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
2019

21-
//Creates a digital signature.
22-
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
20+
//Creates a digital signature.
21+
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
2322

24-
//Sets signature settings to customize digest algorithm specified.
25-
PdfSignatureSettings settings = signature.Settings;
26-
settings.DigestAlgorithm = DigestAlgorithm.SHA256;
23+
//Sets signature settings to customize digest algorithm specified.
24+
PdfSignatureSettings settings = signature.Settings;
25+
settings.DigestAlgorithm = DigestAlgorithm.SHA256;
2726

28-
//Sets an image for signature field.
29-
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
27+
//Sets an image for signature field.
28+
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
3029

31-
//Sets an image for signature field.
32-
PdfBitmap signatureImage = new PdfBitmap(imageStream);
30+
//Sets an image for signature field.
31+
PdfBitmap signatureImage = new PdfBitmap(imageStream);
3332

34-
//Sets signature information.
35-
signature.Bounds = new RectangleF(new PointF(0, 0), signatureImage.PhysicalDimension);
36-
signature.ContactInfo = "[email protected]";
37-
signature.LocationInfo = "Honolulu, Hawaii";
38-
signature.Reason = "I am author of this document.";
33+
//Sets signature information.
34+
signature.Bounds = new RectangleF(new PointF(0, 0), signatureImage.PhysicalDimension);
35+
signature.SignedName = "Syncfusion";
36+
signature.ContactInfo = "[email protected]";
37+
signature.LocationInfo = "Honolulu, Hawaii";
38+
signature.Reason = "I am author of this document.";
3939

40-
//Draws the signature image.
41-
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0);
40+
//Draws the signature image.
41+
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0);
4242

43-
//Create file stream.
44-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
45-
{
46-
//Save the PDF document to file stream.
47-
document.Save(outputFileStream);
48-
}
43+
// Save the PDF document
44+
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
4945

50-
//Close the document.
51-
document.Close(true);
46+
}
Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
using Syncfusion.Drawing;
1+
using Syncfusion.Drawing;
42
using Syncfusion.Pdf;
53
using Syncfusion.Pdf.Graphics;
64
using Syncfusion.Pdf.Security;
75

86
//Creates a new PDF document.
9-
PdfDocument document = new PdfDocument();
7+
using (PdfDocument document = new PdfDocument())
8+
{
109

11-
//Adds a new page.
12-
PdfPageBase page = document.Pages.Add();
10+
//Adds a new page.
11+
PdfPageBase page = document.Pages.Add();
1312

14-
//Create graphics
15-
PdfGraphics graphics = page.Graphics;
13+
//Create graphics
14+
PdfGraphics graphics = page.Graphics;
1615

17-
//Creates a certificate instance from PFX file with private key.
18-
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
19-
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
16+
//Creates a certificate instance from PFX file with private key.
17+
FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read);
18+
PdfCertificate pdfCert = new PdfCertificate(certificateStream, "syncfusion");
2019

21-
//Creates a digital signature.
22-
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
20+
//Creates a digital signature.
21+
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
2322

24-
//Sets signature settings to customize cryptographic standard specified.
25-
PdfSignatureSettings settings = signature.Settings;
26-
settings.CryptographicStandard = CryptographicStandard.CADES;
23+
//Sets signature settings to customize cryptographic standard specified.
24+
PdfSignatureSettings settings = signature.Settings;
25+
settings.CryptographicStandard = CryptographicStandard.CADES;
2726

28-
//Sets an image for signature field.
29-
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
27+
//Sets an image for signature field.
28+
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.png"), FileMode.Open, FileAccess.Read);
3029

31-
//Sets an image for signature field.
32-
PdfBitmap signatureImage = new PdfBitmap(imageStream);
30+
//Sets an image for signature field.
31+
PdfBitmap signatureImage = new PdfBitmap(imageStream);
3332

34-
//Sets signature information
35-
signature.Bounds = new RectangleF(new PointF(0, 0), signatureImage.PhysicalDimension);
36-
signature.ContactInfo = "[email protected]";
37-
signature.LocationInfo = "Honolulu, Hawaii";
38-
signature.Reason = "I am author of this document.";
33+
//Sets signature information
34+
signature.Bounds = new RectangleF(new PointF(0, 0), signatureImage.PhysicalDimension);
35+
signature.SignedName = "Syncfusion";
36+
signature.ContactInfo = "[email protected]";
37+
signature.LocationInfo = "Honolulu, Hawaii";
38+
signature.Reason = "I am author of this document.";
3939

40-
//Draws the signature image.
41-
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0);
40+
//Draws the signature image.
41+
signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0);
4242

43-
//Create file stream.
44-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
45-
{
46-
//Save the PDF document to file stream.
47-
document.Save(outputFileStream);
48-
}
43+
// Save the PDF document
44+
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
4945

50-
//Close the document.
51-
document.Close(true);
46+
}

0 commit comments

Comments
 (0)