diff --git a/PDFRedaction/PDFRedaction/ConsolePopup.xaml b/PDFRedaction/PDFRedaction/ConsolePopup.xaml
new file mode 100644
index 0000000..8001ec3
--- /dev/null
+++ b/PDFRedaction/PDFRedaction/ConsolePopup.xaml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PDFRedaction/PDFRedaction/ConsolePopup.xaml.cs b/PDFRedaction/PDFRedaction/ConsolePopup.xaml.cs
new file mode 100644
index 0000000..32b8581
--- /dev/null
+++ b/PDFRedaction/PDFRedaction/ConsolePopup.xaml.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace PDFRedaction
+{
+ ///
+ /// Interaction logic for ConsolePopup.xaml
+ ///
+ public partial class ConsolePopup : Window
+ {
+ public ConsolePopup()
+ {
+ InitializeComponent();
+ }
+ public void WriteLine(string message)
+ {
+ ConsoleOutput.AppendText(message + Environment.NewLine);
+ ConsoleOutput.ScrollToEnd();
+ }
+ public void Clear()
+ { ConsoleOutput.Clear(); }
+
+ private void CloseButton_Click(object sender, RoutedEventArgs e)
+ {
+ ConsoleOutput.Clear(); // Clear the text
+ this.Close();
+ }
+ }
+}
diff --git a/PDFRedaction/PDFRedaction/Input/input.pdf b/PDFRedaction/PDFRedaction/Input/input.pdf
new file mode 100644
index 0000000..92c51f1
Binary files /dev/null and b/PDFRedaction/PDFRedaction/Input/input.pdf differ
diff --git a/PDFRedaction/PDFRedaction/MainWindow.xaml b/PDFRedaction/PDFRedaction/MainWindow.xaml
index 8d4881d..d631105 100644
--- a/PDFRedaction/PDFRedaction/MainWindow.xaml
+++ b/PDFRedaction/PDFRedaction/MainWindow.xaml
@@ -11,18 +11,32 @@
-
+
This sample demonstrates redacting text and leaving area blank, redacting the text with fill color, redacting the text with redaction codes,
and redacting images in the PDF using OCR.
Click the button to view an PDF document generated by Essential PDF. Please note that Adobe Reader or its equivalent is required to view the resultant document.
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PDFRedaction/PDFRedaction/MainWindow.xaml.cs b/PDFRedaction/PDFRedaction/MainWindow.xaml.cs
index c62fbbf..bcf9b6a 100644
--- a/PDFRedaction/PDFRedaction/MainWindow.xaml.cs
+++ b/PDFRedaction/PDFRedaction/MainWindow.xaml.cs
@@ -4,10 +4,12 @@
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Redaction;
+using System;
using System.Diagnostics;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows;
+using System.Xml.Linq;
namespace PDFRedaction
{
@@ -19,13 +21,14 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
+ Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("NRAiBiAaIQQuGjN/VkZ+XU9FfV5AQmBIYVp/TGpJfl96cVxMZVVBJAtUQF1hTH5Vd0ViUH5XdXxdT2dYWkd2");
}
private void btnRedactPDFwithoutColor(object sender, RoutedEventArgs e)
{
//Load a PDF document for redaction
PdfLoadedDocument ldoc = new PdfLoadedDocument("../../Input/RedactPDFwithEmail.pdf");
-
+
//Get first page from document
PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;
@@ -65,7 +68,7 @@ private void btnRedactPDFwithColor_Click(object sender, RoutedEventArgs e)
Process.Start("RedactedPDF.pdf");
}
- private void btnRedactPDFwithCodes_Click(object sender, RoutedEventArgs e)
+ private void btnRedactPDFwithCodes_Click(object sender, RoutedEventArgs e)
{
//Load a PDF document for redaction
PdfLoadedDocument ldoc = new PdfLoadedDocument("../../Input/W4-tax-form.pdf");
@@ -100,7 +103,7 @@ private void btnRedactPDFwithCodes_Click(object sender, RoutedEventArgs e)
private void btnRedactPDFImage_Click(object sender, RoutedEventArgs e)
{
- using (OCRProcessor processor = new OCRProcessor(@"../../TesseractBinaries/3.02"))
+ using (OCRProcessor processor = new OCRProcessor())
{
//Load the PDF document
PdfLoadedDocument lDoc = new PdfLoadedDocument(@"../../Input/FormWithSSN.pdf");
@@ -128,7 +131,7 @@ private void btnRedactPDFImage_Click(object sender, RoutedEventArgs e)
scaleX = imgInfo.Bounds.Height / ocrImage.Height;
scaleY = imgInfo.Bounds.Width / ocrImage.Width;
}
-
+
//Get the text from page and lines.
foreach (var page in result.Pages)
{
@@ -142,7 +145,7 @@ private void btnRedactPDFImage_Click(object sender, RoutedEventArgs e)
{
RectangleF redactionBound = new RectangleF(line.Rectangle.X * scaleX, line.Rectangle.Y * scaleY,
(line.Rectangle.Width - line.Rectangle.X) * scaleX, (line.Rectangle.Height - line.Rectangle.Y) * scaleY);
-
+
//Create PDF redaction for the found SSN location
PdfRedaction redaction = new PdfRedaction(redactionBound);
@@ -163,5 +166,138 @@ private void btnRedactPDFImage_Click(object sender, RoutedEventArgs e)
Process.Start("RedactedPDF.pdf");
}
}
+
+ private void btnAddVisualElements_Click(object sender, RoutedEventArgs e)
+ {
+ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Input/RedactPDFwithEmail.pdf"))
+ {
+ //Get the first page from the document
+ PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
+
+ //Create a PDF redaction for the page
+ PdfRedaction redaction = new PdfRedaction(new RectangleF(341, 149, 64, 14));
+
+ //Draw the patten on the redaction area
+ PdfHatchBrush pdfHatchBrush = new PdfHatchBrush(PdfHatchStyle.BackwardDiagonal, Color.Red, Color.Transparent);
+
+ redaction.Appearance.Graphics.DrawRectangle(pdfHatchBrush, new RectangleF(0, 0, 64, 14));
+
+ //Add the redaction to the loaded page
+ page.Redactions.Add(redaction);
+
+ //Save the redacted PDF document to disk
+ loadedDocument.Save("RedactedPDFWithVisualAppearance.pdf");
+ //Close the document instance
+ loadedDocument.Close(true);
+
+ Process.Start("RedactedPDFWithVisualAppearance.pdf");
+ }
+
+ }
+
+ private void btnTextOnly_Click(object sender, RoutedEventArgs e)
+ {
+ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Input/RedactPDFwithEmail.pdf"))
+ {
+ //Get the first page from the document
+ PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
+
+ //Create a PDF redaction for the page
+ PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 280, 100, 16));
+
+ //Set text only redaction
+ redaction.TextOnly = true;
+
+ //Add the redaction to the loaded page
+ page.Redactions.Add(redaction);
+
+ //Save the redacted PDF document to disk
+ loadedDocument.Save("RedactedPDFTextOnly.pdf");
+ //Close the document instance
+ loadedDocument.Close(true);
+
+ Process.Start("RedactedPDFTextOnly.pdf");
+ }
+ }
+
+ private void btnFindAndRedact_Click(object sender, RoutedEventArgs e)
+ {
+ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Input/RedactPDFwithEmail.pdf"))
+ {
+ //Get the first page from the document
+ PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
+
+ //Extract text from the page
+ page.ExtractText(out TextLines textLines);
+
+ if (textLines != null && textLines.Count > 0)
+ {
+ //Define regular expression pattern to search for dates in the format MM/DD/YYYY
+ string datePattern = @"\b\d{1,2}\/\d{1,2}\/\d{4}\b";
+
+ //Find the text to redact
+ foreach (TextLine line in textLines)
+ {
+ foreach (TextWord word in line.WordCollection)
+ {
+ //Match the text against the date pattern
+ MatchCollection dateMatches = Regex.Matches(word.Text, datePattern);
+ //Add redaction if the match found
+ foreach (Match dateMatch in dateMatches)
+ {
+ string textToFindAndRedact = dateMatch.Value;
+ if (textToFindAndRedact == word.Text)
+ {
+ //Create a redaction object.
+ PdfRedaction redaction = new PdfRedaction(word.Bounds, Color.Black);
+ //Add a redaction object into the redaction collection of loaded page.
+ page.AddRedaction(redaction);
+ }
+ }
+ }
+
+ }
+ }
+ //Save the redacted PDF document to disk
+ loadedDocument.Save("RedactedPDFRegex.pdf");
+ //Close the document instance
+ loadedDocument.Close(true);
+
+ Process.Start("RedactedPDFRegex.pdf");
+ }
+ }
+
+ private void btnRedactionProgress_Click(object sender, RoutedEventArgs e)
+ {
+ //Load the PDF document for redaction
+ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Input/input.pdf"))
+ {
+ ConsolePopup consolePopup = new ConsolePopup();
+ consolePopup.Show();
+
+ //Set the redaction progress handler to track the progress of redaction
+ loadedDocument.RedactionProgress += (redactSender, args) =>
+ {
+ //Display the progress in the console
+ consolePopup.WriteLine($"Redaction Progress: {args.Progress}%");
+ };
+
+ //Iterate through each page in the document
+ foreach (PdfLoadedPage page in loadedDocument.Pages)
+ {
+ //Create a redaction area for the page
+ PdfRedaction redaction = new PdfRedaction(new RectangleF(120, 200, 140, 20));
+ redaction.Appearance.Graphics.DrawRectangle(PdfBrushes.Black, new RectangleF(0, 0, 140, 20));
+ //Add the redaction to the loaded page
+ page.Redactions.Add(redaction);
+ }
+ //Save the redacted PDF document to disk
+ loadedDocument.Save("RedactedPDFWithProgress.pdf");
+ //Close the document instance
+ loadedDocument.Close(true);
+ //Open the redacted PDF document
+ Process.Start("RedactedPDFWithProgress.pdf");
+ }
+ }
}
}
diff --git a/PDFRedaction/PDFRedaction/PDFRedaction.csproj b/PDFRedaction/PDFRedaction/PDFRedaction.csproj
index fbf953f..8d062f4 100644
--- a/PDFRedaction/PDFRedaction/PDFRedaction.csproj
+++ b/PDFRedaction/PDFRedaction/PDFRedaction.csproj
@@ -36,17 +36,17 @@
4
-
- ..\packages\Syncfusion.Compression.Base.27.1.53\lib\net462\Syncfusion.Compression.Base.dll
+
+ ..\packages\Syncfusion.Compression.Base.30.1.42\lib\net462\Syncfusion.Compression.Base.dll
-
- ..\packages\Syncfusion.Licensing.27.1.53\lib\net462\Syncfusion.Licensing.dll
+
+ ..\packages\Syncfusion.Licensing.30.1.42\lib\net462\Syncfusion.Licensing.dll
-
- ..\packages\Syncfusion.Pdf.OCR.Wpf.27.1.53\lib\net462\Syncfusion.OCRProcessor.Base.dll
+
+ ..\packages\Syncfusion.Pdf.OCR.Wpf.30.1.42\lib\net462\Syncfusion.OCRProcessor.Base.dll
-
- ..\packages\Syncfusion.Pdf.Wpf.27.1.53\lib\net462\Syncfusion.Pdf.Base.dll
+
+ ..\packages\Syncfusion.Pdf.Wpf.30.1.42\lib\net462\Syncfusion.Pdf.Base.dll
@@ -69,6 +69,10 @@
MSBuild:Compile
Designer
+
+ Designer
+ MSBuild:Compile
+
MSBuild:Compile
Designer
@@ -77,6 +81,9 @@
App.xaml
Code
+
+ ConsolePopup.xaml
+
MainWindow.xaml
Code
@@ -110,11 +117,11 @@
-
+
This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
+
\ No newline at end of file
diff --git a/PDFRedaction/PDFRedaction/packages.config b/PDFRedaction/PDFRedaction/packages.config
index 72d9587..2024317 100644
--- a/PDFRedaction/PDFRedaction/packages.config
+++ b/PDFRedaction/PDFRedaction/packages.config
@@ -1,7 +1,7 @@
-
-
-
-
+
+
+
+
\ No newline at end of file