You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: File-Formats/PDF/Working-with-Redaction.md
+152-3Lines changed: 152 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -741,9 +741,9 @@ loadedDocument.Close(True)
741
741
742
742
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Redaction/Get-the-result-of-redaction-with-other-information/).
743
743
744
-
## Redact text content alone on the redated area
744
+
## Redact text content alone on the redacted area
745
745
746
-
You can get the Redact text content alone on the redated area using [RedactionProgress](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html#Syncfusion_Pdf_Parsing_PdfLoadedDocument_RedactionProgress) event in [PdfLoadedDocument](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html) class.
746
+
You can get the Redact text content alone on the redacted area using [RedactionProgress](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html#Syncfusion_Pdf_Parsing_PdfLoadedDocument_RedactionProgress) event in [PdfLoadedDocument](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html) class.
747
747
748
748
The code snippet to illustrate the same is given below.
749
749
@@ -812,4 +812,153 @@ loadedDocument.Close(True)
812
812
813
813
{% endtabs %}
814
814
815
-
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Redaction/Redaction/Redact-text-content-alone-on-the-redated-area/).
815
+
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Redaction/Redact-text-content-alone-on-the-redated-area/).
816
+
817
+
818
+
## Find text by regular expression pattern and redact it from PDF document.
819
+
820
+
You can find text by regular expression pattern and redact it from PDF document using the [PdfRedaction](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Redaction.PdfRedaction.html#Syncfusion_Pdf_Redaction_PdfRedaction__ctor_System_Drawing_RectangleF_) class.
821
+
822
+
The following code snippet explains how to find text by regular expression pattern and redact it from PDF document.
823
+
824
+
{% tabs %}
825
+
826
+
{% highlight c# tabtitle="C# [Cross-platform]" %}
827
+
828
+
//Create stream from an existing PDF document.
829
+
FileStream docStream = new FileStream(Path.GetFullPath("Input.pdf"), FileMode.Open, FileAccess.Read);
830
+
831
+
//Load the existing PDF document.
832
+
PdfLoadedDocument document = new PdfLoadedDocument(docStream);
833
+
834
+
//Get the first page from the document.
835
+
PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;
836
+
837
+
TextLineCollection collection = new TextLineCollection();
Dim docStream As New FileStream(Path.GetFullPath("Input.pdf"), FileMode.Open, FileAccess.Read)
920
+
921
+
'Load the existing PDF document.
922
+
Dim document As New PdfLoadedDocument(docStream)
923
+
924
+
'Get the first page from the document.
925
+
Dim page As PdfLoadedPage = TryCast(document.Pages(0), PdfLoadedPage)
926
+
927
+
Dim collection As New TextLineCollection()
928
+
'Extract text from first page.
929
+
Dim extractedText As String = page.ExtractText(collection)
930
+
931
+
For Each line As TextLine In collection.TextLine
932
+
For Each word As TextWord In line.WordCollection
933
+
'Define regular expression pattern to search for dates in the format MM/DD/YYYY
934
+
Dim datePattern As String = "\b\d{1,2}\/\d{1,2}\/\d{4}\b"
935
+
'Search for dates
936
+
Dim dateMatches As MatchCollection = Regex.Matches(word.Text, datePattern)
937
+
'Add redaction if the match found
938
+
For Each dateMatch As Match In dateMatches
939
+
Dim textToFindAndRedact As String = dateMatch.Value
940
+
If textToFindAndRedact = word.Text Then
941
+
'Create a redaction object.
942
+
Dim redaction As New PdfRedaction(word.Bounds, Syncfusion.Drawing.Color.Black)
943
+
'Add a redaction object into the redaction collection of loaded page.
944
+
page.AddRedaction(redaction)
945
+
End If
946
+
Next
947
+
Next
948
+
Next
949
+
950
+
'Redact the contents from the PDF document.
951
+
document.Redact()
952
+
953
+
'Creating the stream object
954
+
Dim stream As New MemoryStream()
955
+
'Save the document
956
+
document.Save(stream)
957
+
'Close the document
958
+
document.Close(True)
959
+
960
+
{% endhighlight %}
961
+
962
+
{% endtabs %}
963
+
964
+
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Redaction/Find-text-by-regular-expression-pattern-and-redact-it-from-PDF-document/.NET-Standard).
0 commit comments