Skip to content

Commit d6f0090

Browse files
author
Sowmiya Loganathan
committed
Add digital signature samples
1 parent 47ff7dd commit d6f0090

File tree

20 files changed

+301
-0
lines changed

20 files changed

+301
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32819.101
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multiple-digital-signature", "Multiple-digital-signature\Multiple-digital-signature.csproj", "{1CBB87CB-9DA9-402C-B4C6-5689C8BBD562}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1CBB87CB-9DA9-402C-B4C6-5689C8BBD562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1CBB87CB-9DA9-402C-B4C6-5689C8BBD562}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1CBB87CB-9DA9-402C-B4C6-5689C8BBD562}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1CBB87CB-9DA9-402C-B4C6-5689C8BBD562}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {6A4F1F24-46E9-4E32-8DC7-54D8A5A39FE4}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>Multiple_digital_signature</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.NET" Version="20.3.0.60" />
13+
</ItemGroup>
14+
15+
</Project>
Binary file not shown.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using Syncfusion.Pdf.Graphics;
4+
using Syncfusion.Pdf.Parsing;
5+
using Syncfusion.Pdf.Security;
6+
using Syncfusion.Pdf;
7+
8+
//Load an existing PDF document.
9+
FileStream docStream = new FileStream(Path.GetFullPath("../../../SignatureFields.pdf"), FileMode.Open, FileAccess.Read);
10+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
11+
12+
//Get the first page of the document.
13+
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
14+
15+
//Get the first signature field of the PDF document.
16+
PdfLoadedSignatureField signatureField1 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
17+
18+
//Create a certificate instance from a PFX file with a private key.
19+
FileStream certificateStream = new FileStream(Path.GetFullPath("../../../PDF.pfx"), FileMode.Open, FileAccess.Read);
20+
PdfCertificate certificate1 = new PdfCertificate(certificateStream, "syncfusion");
21+
22+
//Add a signature to the signature field.
23+
signatureField1.Signature = new PdfSignature(loadedDocument, page, certificate1, "Signature", signatureField1);
24+
25+
//Set an image for the signature field.
26+
FileStream imageStream1 = new FileStream(Path.GetFullPath("../../../Student Signature.jpg"), FileMode.Open, FileAccess.Read);
27+
PdfBitmap signatureImage = new PdfBitmap(imageStream1);
28+
29+
//Insert an image in the signature appearance.
30+
signatureField1.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, 90, 20);
31+
32+
//Save the document into the stream.
33+
MemoryStream stream = new MemoryStream();
34+
loadedDocument.Save(stream);
35+
36+
//Load the signed PDF document.
37+
PdfLoadedDocument signedDocument = new PdfLoadedDocument(stream);
38+
39+
//Load the PDF page.
40+
PdfLoadedPage loadedPage = signedDocument.Pages[0] as PdfLoadedPage;
41+
42+
//Get the first signature field of the PDF document.
43+
PdfLoadedSignatureField signatureField2 = signedDocument.Form.Fields[1] as PdfLoadedSignatureField;
44+
45+
//Add a signature to the signature field.
46+
signatureField2.Signature = new PdfSignature(signedDocument, loadedPage, certificate1, "Signature", signatureField2);
47+
48+
//Set an image for the signature field.
49+
FileStream imageStream2 = new FileStream(Path.GetFullPath("../../../Teacher Signature.png"), FileMode.Open, FileAccess.Read);
50+
PdfBitmap signatureImage1 = new PdfBitmap(imageStream2);
51+
52+
//Draw an image in the signature appearance.
53+
signatureField2.Signature.Appearance.Normal.Graphics.DrawImage(signatureImage1, 0, 0, 90, 20);
54+
55+
//Create file stream.
56+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
57+
{
58+
//Save the PDF document to file stream.
59+
signedDocument.Save(outputFileStream);
60+
}
61+
62+
//Close the document.
63+
signedDocument.Close(true);
64+
loadedDocument.Close(true);
Binary file not shown.
10.8 KB
Loading
4.13 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32819.101
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Remove_existing_digital_signature_from_PDF", "Remove_existing_digital_signature_from_PDF\Remove_existing_digital_signature_from_PDF.csproj", "{78A40DE4-F2D5-44A1-9599-C166318E805B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{78A40DE4-F2D5-44A1-9599-C166318E805B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{78A40DE4-F2D5-44A1-9599-C166318E805B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{78A40DE4-F2D5-44A1-9599-C166318E805B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{78A40DE4-F2D5-44A1-9599-C166318E805B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3D8228EC-6D8B-4F32-98BC-68E5CE7E2650}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using Syncfusion.Pdf.Parsing;
4+
5+
//Load an existing PDF document.
6+
FileStream docStream = new FileStream(Path.GetFullPath("../../../SignedPDF.pdf"), FileMode.Open, FileAccess.Read);
7+
PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(docStream);
8+
9+
//Get the signature field from PDF form field collection.
10+
PdfLoadedSignatureField signatureField = pdfLoadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
11+
12+
//Remove signature field from form field collection.
13+
pdfLoadedDocument.Form.Fields.Remove(signatureField);
14+
15+
//Create file stream.
16+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
17+
{
18+
//Save the PDF document to file stream.
19+
pdfLoadedDocument.Save(outputFileStream);
20+
}
21+
22+
//Close the document.
23+
pdfLoadedDocument.Close(true);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.Pdf.NET" Version="20.3.0.60" />
12+
</ItemGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)