Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36408.4 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7EAC121E-76EB-4D12-AF60-D457BE069660}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EAC121E-76EB-4D12-AF60-D457BE069660}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EAC121E-76EB-4D12-AF60-D457BE069660}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EAC121E-76EB-4D12-AF60-D457BE069660}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AC2186CF-C132-4B74-9E9B-995A2480B219}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Adding_quad_points_to_existing_redaction_annotations</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Syncfusion.Drawing;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;

// Load the existing PDF document using FileStream
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read))
{
// Load the PDF document from the input stream
using (PdfLoadedDocument ldoc = new PdfLoadedDocument(inputStream))
{
//Load the existing PdfLoadedRedactionAnnotation
PdfLoadedRedactionAnnotation annot = ldoc.Pages[0].Annotations[0] as PdfLoadedRedactionAnnotation;

//set the bounds
List<RectangleF> bounds = new List<RectangleF>();
bounds.Add(new RectangleF(100, 100, 50, 20));
bounds.Add(new RectangleF(200, 150, 60, 25));
annot.BoundsCollection = bounds;

//set the inner color
annot.InnerColor = Color.Black;
//set the border color
annot.BorderColor = Color.Green;
//set the text color
annot.TextColor = Color.Yellow;
//set the font
annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
//set overlay text
annot.OverlayText = "Redact";
//set text alignment
annot.TextAlignment = PdfTextAlignment.Center;
annot.RepeatText = true;

// Save the modified document using a new FileStream
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write))
{
// Save changes to a new PDF file
ldoc.Save(outputStream);
}
// Close the document and release resources
ldoc.Close(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36408.4 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4ACF1F8B-A43B-4148-9452-0587200478F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4ACF1F8B-A43B-4148-9452-0587200478F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4ACF1F8B-A43B-4148-9452-0587200478F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4ACF1F8B-A43B-4148-9452-0587200478F8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {735E1E3B-6CCF-41EC-9ABA-187BF9AA9851}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Multi_line_text_redaction_using_quad_points</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;

//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Create a new page.
PdfPage page = document.Pages.Add();
//Creates a new Redaction annotation.
PdfRedactionAnnotation annot = new PdfRedactionAnnotation();

//set the bounds collection of redaction annotation.
List<RectangleF> bounds = new List<RectangleF>();
bounds.Add(new RectangleF(100, 100, 50, 20));
bounds.Add(new RectangleF(200, 150, 60, 25));
annot.BoundsCollection = bounds;

//set the innercolor
annot.InnerColor = Color.Black;
//set the bordercolor
annot.BorderColor = Color.Green;
//set the textcolor
annot.TextColor = Color.Yellow;
//set the font
annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
//set overlaytext
annot.OverlayText = "Redact";
//set text alignment
annot.TextAlignment = PdfTextAlignment.Right;
//Assign the RepeatText
annot.RepeatText = true;

//Add the annotation to the page.
page.Annotations.Add(annot);


// Save the modified document using a new FileStream
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write))
{
// Save changes to a new PDF file
document.Save(outputStream);
}
// Close the document and release resources
document.Close(true);
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,80 @@
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;

namespace Externally_sign_the_PDF_document {
internal class Program {
static void Main(string[] args) {
//Get the stream from the document
FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Barcode.pdf"), FileMode.Open, FileAccess.Read);
//Load the existing PDF document
namespace Externally_sign_the_PDF_document
{
internal class Program
{
static void Main(string[] args)
{
// Get the stream from the document
FileStream documentStream = new FileStream(Path.GetFullPath(@"../../../Data/Barcode.pdf"), FileMode.Open, FileAccess.Read);

// Load the existing PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);

//Creates a digital signature.
// Create a digital signature
PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], null, "Signature");
//Sets the signature information.

// Set the signature information
signature.Bounds = new RectangleF(new PointF(0, 0), new SizeF(100, 30));
signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA1;

//Create an external signer.
// Create an external signer
IPdfExternalSigner externalSignature = new ExternalSigner("SHA1");

//Add public certificates.
// Add public certificates
List<X509Certificate2> certificates = new List<X509Certificate2>();
certificates.Add(new X509Certificate2(new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "password123")));
certificates.Add(new X509Certificate2(Path.GetFullPath(@"../../../Data/PDF.pfx"), "password123"));
signature.AddExternalSigner(externalSignature, certificates, null);

//Create file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) {
//Save the PDF document to file stream.
// Create file stream
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
// Save the PDF document to file stream
loadedDocument.Save(outputFileStream);
}
//Close the document.

// Close the document
loadedDocument.Close(true);
}
//Create the external signer class and sign the document hash.
class ExternalSigner : IPdfExternalSigner {

// Create the external signer class and sign the document hash
class ExternalSigner : IPdfExternalSigner
{
private string _hashAlgorithm;
public string HashAlgorithm {

public string HashAlgorithm
{
get { return _hashAlgorithm; }
}

public ExternalSigner(string hashAlgorithm) {
public ExternalSigner(string hashAlgorithm)
{
_hashAlgorithm = hashAlgorithm;
}
public byte[] Sign(byte[] message, out byte[] timeStampResponse) {

public byte[] Sign(byte[] message, out byte[] timeStampResponse)
{
timeStampResponse = null;
X509Certificate2 digitalID = new X509Certificate2(new X509Certificate2(Path.GetFullPath(@"Data/PDF.pfx"), "password123"));
if (digitalID.PrivateKey is System.Security.Cryptography.RSACryptoServiceProvider) {
System.Security.Cryptography.RSACryptoServiceProvider rsa = (System.Security.Cryptography.RSACryptoServiceProvider)digitalID.PrivateKey;
return rsa.SignData(message, HashAlgorithm);
X509Certificate2 digitalID = new X509Certificate2(Path.GetFullPath(@"../../../Data/PDF.pfx"), "password123");

if (digitalID.PrivateKey is RSACryptoServiceProvider rsaProvider)
{
return rsaProvider.SignData(message, HashAlgorithm);
}
else if (digitalID.PrivateKey is RSACng) {
RSACng rsa = (RSACng)digitalID.PrivateKey;
return rsa.SignData(message, System.Security.Cryptography.HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
else if (digitalID.PrivateKey is RSACng rsaCng)
{
return rsaCng.SignData(message, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
}
else if (digitalID.PrivateKey is RSAOpenSsl rsaOpenSsl)
{
return rsaOpenSsl.SignData(message, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
}

return null;
}
}
}
}
}
Loading