Skip to content

Commit e55dbfb

Browse files
Merge pull request #196 from SyncfusionExamples/980802
980802: Updated GitHub sample code in PDF Example branch.
2 parents baa6185 + 90211ee commit e55dbfb

11 files changed

Lines changed: 217 additions & 28 deletions

File tree

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.14.36408.4 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adding-quad-points-to-existing-redaction-annotations", "Adding-quad-points-to-existing-redaction-annotations\Adding-quad-points-to-existing-redaction-annotations.csproj", "{7EAC121E-76EB-4D12-AF60-D457BE069660}"
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+
{7EAC121E-76EB-4D12-AF60-D457BE069660}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7EAC121E-76EB-4D12-AF60-D457BE069660}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7EAC121E-76EB-4D12-AF60-D457BE069660}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7EAC121E-76EB-4D12-AF60-D457BE069660}.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 = {AC2186CF-C132-4B74-9E9B-995A2480B219}
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>net8.0</TargetFramework>
6+
<RootNamespace>Adding_quad_points_to_existing_redaction_annotations</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>

Annotation/Adding-quad-points-to-existing-redaction-annotations/.NET/Adding-quad-points-to-existing-redaction-annotations/Output/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Pdf.Graphics;
3+
using Syncfusion.Pdf.Interactive;
4+
using Syncfusion.Pdf.Parsing;
5+
6+
// Load the existing PDF document using FileStream
7+
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read))
8+
{
9+
// Load the PDF document from the input stream
10+
using (PdfLoadedDocument ldoc = new PdfLoadedDocument(inputStream))
11+
{
12+
//Load the existing PdfLoadedRedactionAnnotation
13+
PdfLoadedRedactionAnnotation annot = ldoc.Pages[0].Annotations[0] as PdfLoadedRedactionAnnotation;
14+
15+
//set the bounds
16+
List<RectangleF> bounds = new List<RectangleF>();
17+
bounds.Add(new RectangleF(100, 100, 50, 20));
18+
bounds.Add(new RectangleF(200, 150, 60, 25));
19+
annot.BoundsCollection = bounds;
20+
21+
//set the inner color
22+
annot.InnerColor = Color.Black;
23+
//set the border color
24+
annot.BorderColor = Color.Green;
25+
//set the text color
26+
annot.TextColor = Color.Yellow;
27+
//set the font
28+
annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
29+
//set overlay text
30+
annot.OverlayText = "Redact";
31+
//set text alignment
32+
annot.TextAlignment = PdfTextAlignment.Center;
33+
annot.RepeatText = true;
34+
35+
// Save the modified document using a new FileStream
36+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write))
37+
{
38+
// Save changes to a new PDF file
39+
ldoc.Save(outputStream);
40+
}
41+
// Close the document and release resources
42+
ldoc.Close(true);
43+
}
44+
}
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.14.36408.4 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multi-line-text-redaction-using-quad-points", "Multi-line-text-redaction-using-quad-points\Multi-line-text-redaction-using-quad-points.csproj", "{4ACF1F8B-A43B-4148-9452-0587200478F8}"
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+
{4ACF1F8B-A43B-4148-9452-0587200478F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4ACF1F8B-A43B-4148-9452-0587200478F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4ACF1F8B-A43B-4148-9452-0587200478F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4ACF1F8B-A43B-4148-9452-0587200478F8}.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 = {735E1E3B-6CCF-41EC-9ABA-187BF9AA9851}
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>net8.0</TargetFramework>
6+
<RootNamespace>Multi_line_text_redaction_using_quad_points</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>

Annotation/Multi-line-text-redaction-using-quad-points/.NET/Multi-line-text-redaction-using-quad-points/Output/.gitkeep

Whitespace-only changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Pdf.Graphics;
4+
using Syncfusion.Pdf.Interactive;
5+
6+
//Create a new PDF document.
7+
PdfDocument document = new PdfDocument();
8+
//Create a new page.
9+
PdfPage page = document.Pages.Add();
10+
//Creates a new Redaction annotation.
11+
PdfRedactionAnnotation annot = new PdfRedactionAnnotation();
12+
13+
//set the bounds collection of redaction annotation.
14+
List<RectangleF> bounds = new List<RectangleF>();
15+
bounds.Add(new RectangleF(100, 100, 50, 20));
16+
bounds.Add(new RectangleF(200, 150, 60, 25));
17+
annot.BoundsCollection = bounds;
18+
19+
//set the innercolor
20+
annot.InnerColor = Color.Black;
21+
//set the bordercolor
22+
annot.BorderColor = Color.Green;
23+
//set the textcolor
24+
annot.TextColor = Color.Yellow;
25+
//set the font
26+
annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
27+
//set overlaytext
28+
annot.OverlayText = "Redact";
29+
//set text alignment
30+
annot.TextAlignment = PdfTextAlignment.Right;
31+
//Assign the RepeatText
32+
annot.RepeatText = true;
33+
34+
//Add the annotation to the page.
35+
page.Annotations.Add(annot);
36+
37+
38+
// Save the modified document using a new FileStream
39+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write))
40+
{
41+
// Save changes to a new PDF file
42+
document.Save(outputStream);
43+
}
44+
// Close the document and release resources
45+
document.Close(true);

Digital Signature/Externally-sign-the-PDF-document-using-IPdfExternalSigner/.NET/Externally-sign-the-PDF-document/Program.cs

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,80 @@
44
using System.Security.Cryptography.X509Certificates;
55
using System.Security.Cryptography;
66

7-
namespace Externally_sign_the_PDF_document {
8-
internal class Program {
9-
static void Main(string[] args) {
10-
//Get the stream from the document
11-
FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Barcode.pdf"), FileMode.Open, FileAccess.Read);
12-
//Load the existing PDF document
7+
namespace Externally_sign_the_PDF_document
8+
{
9+
internal class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
// Get the stream from the document
14+
FileStream documentStream = new FileStream(Path.GetFullPath(@"../../../Data/Barcode.pdf"), FileMode.Open, FileAccess.Read);
15+
16+
// Load the existing PDF document
1317
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);
1418

15-
//Creates a digital signature.
19+
// Create a digital signature
1620
PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], null, "Signature");
17-
//Sets the signature information.
21+
22+
// Set the signature information
1823
signature.Bounds = new RectangleF(new PointF(0, 0), new SizeF(100, 30));
1924
signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
2025
signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA1;
2126

22-
//Create an external signer.
27+
// Create an external signer
2328
IPdfExternalSigner externalSignature = new ExternalSigner("SHA1");
2429

25-
//Add public certificates.
30+
// Add public certificates
2631
List<X509Certificate2> certificates = new List<X509Certificate2>();
27-
certificates.Add(new X509Certificate2(new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "password123")));
32+
certificates.Add(new X509Certificate2(Path.GetFullPath(@"../../../Data/PDF.pfx"), "password123"));
2833
signature.AddExternalSigner(externalSignature, certificates, null);
2934

30-
//Create file stream.
31-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) {
32-
//Save the PDF document to file stream.
35+
// Create file stream
36+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
37+
{
38+
// Save the PDF document to file stream
3339
loadedDocument.Save(outputFileStream);
3440
}
35-
//Close the document.
41+
42+
// Close the document
3643
loadedDocument.Close(true);
3744
}
38-
//Create the external signer class and sign the document hash.
39-
class ExternalSigner : IPdfExternalSigner {
45+
46+
// Create the external signer class and sign the document hash
47+
class ExternalSigner : IPdfExternalSigner
48+
{
4049
private string _hashAlgorithm;
41-
public string HashAlgorithm {
50+
51+
public string HashAlgorithm
52+
{
4253
get { return _hashAlgorithm; }
4354
}
4455

45-
public ExternalSigner(string hashAlgorithm) {
56+
public ExternalSigner(string hashAlgorithm)
57+
{
4658
_hashAlgorithm = hashAlgorithm;
4759
}
48-
public byte[] Sign(byte[] message, out byte[] timeStampResponse) {
60+
61+
public byte[] Sign(byte[] message, out byte[] timeStampResponse)
62+
{
4963
timeStampResponse = null;
50-
X509Certificate2 digitalID = new X509Certificate2(new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "password123"));
51-
if (digitalID.PrivateKey is System.Security.Cryptography.RSACryptoServiceProvider) {
52-
System.Security.Cryptography.RSACryptoServiceProvider rsa = (System.Security.Cryptography.RSACryptoServiceProvider)digitalID.PrivateKey;
53-
return rsa.SignData(message, HashAlgorithm);
64+
X509Certificate2 digitalID = new X509Certificate2(Path.GetFullPath(@"../../../Data/PDF.pfx"), "password123");
65+
66+
if (digitalID.PrivateKey is RSACryptoServiceProvider rsaProvider)
67+
{
68+
return rsaProvider.SignData(message, HashAlgorithm);
5469
}
55-
else if (digitalID.PrivateKey is RSACng) {
56-
RSACng rsa = (RSACng)digitalID.PrivateKey;
57-
return rsa.SignData(message, System.Security.Cryptography.HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
70+
else if (digitalID.PrivateKey is RSACng rsaCng)
71+
{
72+
return rsaCng.SignData(message, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
5873
}
74+
else if (digitalID.PrivateKey is RSAOpenSsl rsaOpenSsl)
75+
{
76+
return rsaOpenSsl.SignData(message, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
77+
}
78+
5979
return null;
6080
}
6181
}
6282
}
63-
}
83+
}

0 commit comments

Comments
 (0)