Skip to content

Commit 83a92d3

Browse files
author
Sowmiya Loganathan
committed
Committed the sample
1 parent 55b53f5 commit 83a92d3

File tree

29 files changed

+512
-0
lines changed

29 files changed

+512
-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.1.32407.343
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Deferred-signing-in-PDF-document", "Deferred-signing-in-PDF-document\Deferred-signing-in-PDF-document.csproj", "{5BEAE687-F001-4BAD-8A88-D890659A9F9B}"
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+
{5BEAE687-F001-4BAD-8A88-D890659A9F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5BEAE687-F001-4BAD-8A88-D890659A9F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5BEAE687-F001-4BAD-8A88-D890659A9F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5BEAE687-F001-4BAD-8A88-D890659A9F9B}.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 = {2F087142-046B-4F86-9730-7EF39B6B4608}
24+
EndGlobalSection
25+
EndGlobal
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>Deferred_signing_in_PDF_document</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="20.2.0.50" />
13+
</ItemGroup>
14+
15+
</Project>
Binary file not shown.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using Syncfusion.Drawing;
4+
using Syncfusion.Pdf.Parsing;
5+
using Syncfusion.Pdf.Security;
6+
using System.Security.Cryptography;
7+
using System.Security.Cryptography.X509Certificates;
8+
9+
class Program
10+
{
11+
public static string PublicCert = "MIIDFTCCAf2gAwIBAgIQMjdwZGujtplDiSGarQzO1DANBgkqhkiG9w0BAQsFADAXMRUwEwYDVQQDEwxUZXN0Q2VydFJvb3QwHhcNMTkwOTA5MDg0MzM5WhcNMzkxMjMxMjM1OTU5WjAXMRUwEwYDVQQDEwxUZXN0Q2VydFJvb3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCWs+BZKfWf5cZauYDpXPlHUZour4oNaGoAfySXUD28KLNxCI6AWlK+UV+JJWgcrJ9SpLuoxQb1384gZhQMe4RFtILQpxx9nAxtwsd7/6OLI4G9TRIdy6PJ2OHyHKL9ZqI/+XkUbgznUF9o0F2VlQwszSCQREDQ5PxcGy/GWS71ZT1tvs8iqMVi3PCUH8ERwqTwIhWvRt6weVZ/daR9rNqkEPkpT5tQPMGvmqEinxbjpO8h8gU91rXbiHaY7QlDgCmEy3zWVIROR56x3ZJv5/xjJ/ya4X51P3DcLNGgUTRre0cYXHfnyTQAVFDGxEGsTd4xOnMWrbMaoeRBt8dtBGNBAgMBAAGjXTBbMA8GA1UdEwEB/wQFMAMBAf8wSAYDVR0BBEEwP4AQk/aIkhJaRQ2nRg1ECf13f6EZMBcxFTATBgNVBAMTDFRlc3RDZXJ0Um9vdIIQMjdwZGujtplDiSGarQzO1DANBgkqhkiG9w0BAQsFAAOCAQEAbcFInTXT+08eV1JyrkMsR3HZGtPXyAGRSiZkMJJKE1MU79fFXCiQf6/UpCV76vdCCSOrZLJweUeZPLznZhOxu9aEGnA0CPEcphYUVT9J8aV8MpQJu5DKGbphdBuZNlBQvVg9Yxs0T7Ne49S3s2EUL/w6tFoBuGh1ar9rc3IRmJA8WM2orz4Q8bVhYdtlxWynfx3idCv7pQDymHmB0Wt5iSlcAfcDrZb7YSq+VYIHzAZatefjGRSsbRuVpSfz3dt+cVttKbY3mOWD4zaUvPvKs6bWznxStEBHomcWd3DymekC78aI9XKLmetddpzx6eOgf9Vju8KuO+udGDpoPy2apw==";
12+
public static byte[] SignedHash = null;
13+
public static byte[] SignedHash2 = null;
14+
15+
static void Main(string[] args)
16+
{
17+
//Register Syncfusion license
18+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MDAxQDMyMzAyZTMyMmUzMEpFWWZ3RUVveVJLeWJNTmpSaU5Gd0crYXpISyszcWxNcGo2QzVaRnd4aW89");
19+
20+
CreateEmptySignedPDF();
21+
DeferredSign();
22+
}
23+
24+
static void CreateEmptySignedPDF()
25+
{
26+
// Get the stream from the document.
27+
FileStream documentStream = new FileStream(Path.GetFullPath("../../../Barcode.pdf"), FileMode.Open, FileAccess.Read);
28+
29+
//Load an existing PDF document.
30+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);
31+
32+
//Creates a digital signature.
33+
PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], null, "Signature");
34+
35+
//Sets the signature information.
36+
signature.Bounds = new RectangleF(new PointF(0, 0), new SizeF(100, 30));
37+
signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
38+
signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA1;
39+
40+
//Create an external signer.
41+
IPdfExternalSigner externalSignature = new SignEmpty("SHA1");
42+
43+
//Add public certificates.
44+
System.Collections.Generic.List<X509Certificate2> certificates = new System.Collections.Generic.List<X509Certificate2>();
45+
certificates.Add(new X509Certificate2(Convert.FromBase64String(PublicCert)));
46+
signature.AddExternalSigner(externalSignature, certificates, null);
47+
48+
//Save the document.
49+
FileStream inputFileStream = new FileStream(Path.GetFullPath("../../../EmptySignature.pdf"), FileMode.Create, FileAccess.ReadWrite);
50+
loadedDocument.Save(inputFileStream);
51+
52+
//Close the PDF document.
53+
loadedDocument.Close(true);
54+
inputFileStream.Close();
55+
}
56+
57+
static void DeferredSign()
58+
{
59+
//Create an external signer with a signed hash message.
60+
IPdfExternalSigner externalSigner = new ExternalSigner("SHA1", Program.SignedHash);
61+
62+
//Add public certificates.
63+
System.Collections.Generic.List<X509Certificate2> publicCertificates = new System.Collections.Generic.List<X509Certificate2>();
64+
publicCertificates.Add(new X509Certificate2(Convert.FromBase64String(PublicCert)));
65+
66+
//Create an output file stream.
67+
FileStream outputFileStream = new FileStream(Path.GetFullPath("../../../DeferredSign.pdf"), FileMode.Create, FileAccess.ReadWrite);
68+
69+
// Get the stream from the document
70+
FileStream inputFileStream = new FileStream(Path.GetFullPath("../../../EmptySignature.pdf"), FileMode.Open, FileAccess.Read);
71+
72+
string pdfPassword = string.Empty;
73+
74+
//Replace an empty signature.
75+
PdfSignature.ReplaceEmptySignature(inputFileStream, pdfPassword, outputFileStream, "Signature", externalSigner, publicCertificates);
76+
77+
outputFileStream.Close();
78+
}
79+
80+
/// <summary>
81+
/// Represents to sign an empty signature from the external signer.
82+
/// </summary>
83+
class SignEmpty : IPdfExternalSigner
84+
{
85+
private string _hashAlgorithm;
86+
87+
public string HashAlgorithm
88+
{
89+
get { return _hashAlgorithm; }
90+
}
91+
92+
public SignEmpty(string hashAlgorithm)
93+
{
94+
_hashAlgorithm = hashAlgorithm;
95+
}
96+
97+
public byte[] Sign(byte[] message, out byte[] timeStampResponse)
98+
{
99+
//Send document hash for signing using the external services.
100+
SignDocumentHash(message);
101+
//Set a null value to create an empty signed document.
102+
byte[] signedBytes = null;
103+
timeStampResponse = null;
104+
return signedBytes;
105+
}
106+
//Example for signed docuement hash
107+
private void SignDocumentHash(byte[] documentHash)
108+
{
109+
X509Certificate2 digitalID = new X509Certificate2(new X509Certificate2(Path.GetFullPath("../../../PDF.pfx"), "password123"));
110+
if (digitalID.PrivateKey is System.Security.Cryptography.RSACryptoServiceProvider)
111+
{
112+
System.Security.Cryptography.RSACryptoServiceProvider rsa = (System.Security.Cryptography.RSACryptoServiceProvider)digitalID.PrivateKey;
113+
Program.SignedHash = rsa.SignData(documentHash, HashAlgorithm);
114+
}
115+
else if (digitalID.PrivateKey is RSACng)
116+
{
117+
RSACng rsa = (RSACng)digitalID.PrivateKey;
118+
Program.SignedHash = rsa.SignData(documentHash, System.Security.Cryptography.HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
119+
}
120+
}
121+
}
122+
/// <summary>
123+
/// Represents to replace an empty signature from an external signer.
124+
/// </summary>
125+
class ExternalSigner : IPdfExternalSigner
126+
{
127+
private string _hashAlgorithm;
128+
private byte[] _signedHash;
129+
public string HashAlgorithm
130+
{
131+
get { return _hashAlgorithm; }
132+
}
133+
134+
public ExternalSigner(string hashAlgorithm, byte[] hash)
135+
{
136+
_hashAlgorithm = hashAlgorithm;
137+
_signedHash = hash;
138+
}
139+
140+
public byte[] Sign(byte[] message, out byte[] timeStampResponse)
141+
{
142+
//Set the signed hash message to replace an empty signature.
143+
byte[] signedBytes = _signedHash;
144+
timeStampResponse = null;
145+
return signedBytes;
146+
}
147+
}
148+
}
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.1.32407.343
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Get-option-value-from-acroform-radio-button", "Get-option-value-from-acroform-radio-button\Get-option-value-from-acroform-radio-button.csproj", "{0B1D624A-F9A4-4973-BEC2-C4EAF29D54A6}"
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+
{0B1D624A-F9A4-4973-BEC2-C4EAF29D54A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0B1D624A-F9A4-4973-BEC2-C4EAF29D54A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0B1D624A-F9A4-4973-BEC2-C4EAF29D54A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0B1D624A-F9A4-4973-BEC2-C4EAF29D54A6}.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 = {9FD8C59B-585A-4DA8-B2FD-547547EF839E}
24+
EndGlobalSection
25+
EndGlobal
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>Get_option_value_from_acroform_radio_button</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.NET" Version="20.1.0.52" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using Syncfusion.Pdf.Parsing;
4+
5+
//Get stream from an existing PDF document.
6+
FileStream docStream = new FileStream(Path.GetFullPath("../../../Input.pdf"), FileMode.Open, FileAccess.Read);
7+
8+
//Load the PDF document.
9+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
10+
11+
//Gets the loaded form.
12+
PdfLoadedForm form = loadedDocument.Form;
13+
14+
//Set default appearance to false.
15+
form.SetDefaultAppearance(false);
16+
17+
//Gets the 'Gender' radio button field.
18+
PdfLoadedRadioButtonListField radioButtonField = form.Fields["SF182[0].#subform[0].P1BCheck[0]"] as PdfLoadedRadioButtonListField;
19+
20+
//Select the item that contains option value as "Male".
21+
foreach (PdfLoadedRadioButtonItem item in radioButtonField.Items)
22+
{
23+
//Gets an option value of the item.
24+
if (item.OptionValue == "Resubmission")
25+
{
26+
item.Selected = true;
27+
}
28+
29+
}
30+
31+
//Create file stream.
32+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
33+
{
34+
//Save the PDF document to file stream.
35+
loadedDocument.Save(outputFileStream);
36+
}
37+
38+
//Close the document.
39+
loadedDocument.Close(true);
40+
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}") = "Add-a-hyperlink-in-a-table-cell", "Add-a-hyperlink-in-a-table-cell\Add-a-hyperlink-in-a-table-cell.csproj", "{7827ACF2-FCB7-40A1-A3A1-E80A1E2CE7DC}"
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+
{7827ACF2-FCB7-40A1-A3A1-E80A1E2CE7DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7827ACF2-FCB7-40A1-A3A1-E80A1E2CE7DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7827ACF2-FCB7-40A1-A3A1-E80A1E2CE7DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7827ACF2-FCB7-40A1-A3A1-E80A1E2CE7DC}.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 = {D66335F7-D936-4F63-A8ED-13DEFFD0FFC4}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)