Skip to content

Commit bea5d43

Browse files
committed
980802: Updated GitHub sample code in PDF Example branch.
1 parent baa6185 commit bea5d43

6 files changed

Lines changed: 134 additions & 27 deletions

File tree

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: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,82 @@
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
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
1114
FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Barcode.pdf"), FileMode.Open, FileAccess.Read);
12-
//Load the existing PDF document
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+
65+
FileStream certificateStream = new FileStream("PDF.pfx", FileMode.Open, FileAccess.Read);
66+
X509Certificate2 digitalID = new X509Certificate2(certificateStream, "password123");
67+
68+
if (digitalID.PrivateKey is System.Security.Cryptography.RSACryptoServiceProvider rsaProvider)
69+
{
70+
return rsaProvider.SignData(message, HashAlgorithm);
5471
}
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);
72+
else if (digitalID.PrivateKey is RSACng rsaCng)
73+
{
74+
return rsaCng.SignData(message, System.Security.Cryptography.HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
5875
}
76+
else if (digitalID.PrivateKey is System.Security.Cryptography.RSAOpenSsl rsaOpenSsl)
77+
{
78+
return rsaOpenSsl.SignData(message, System.Security.Cryptography.HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
79+
}
80+
5981
return null;
6082
}
6183
}
6284
}
63-
}
85+
}

Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Output/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)