We are using Aspose.PDF (.NET 19.11 version) for searching and redacting Credit Card numbers.
Problem: The redaction is incomplete on two valid ccn what TextFragmentAbsorber found with the “(?:\d[ -]*){10,19}” regex.
The two ccn:
10011 212-847-4915
35209 205-276-1807
The redacted parts:
10011 2
35209 2
What I found is the Textfragment contains the whole ccn but for some reason, the segments contain a part of the number and the Textfragment Rectangle URX, URY positions are the same as the last TextSegment Rectangle URX, URY. So I cannot set the correct rectangle for the RedactionAnnotation.
Can you please share source code so that we may further investigate to help you out. Also please try to use Aspose.PDF latest version 20.1 on your end before sharing requested information with us.
@Adnan.Ahmad
I tried with the latest version (20.1) but it didn’t solve the problem.
Document tempDocument = new Document(sourcePath);
foreach (Page actualPage in tempDocument.Pages)
{
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(@"(?:\d[ -]*){10,19}");
textFragmentAbsorber.TextSearchOptions.IsRegularExpressionUsed = true;
actualPage.Accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach (TextFragment textFragment in textFragmentCollection)
{
Rectangle rect = textFragment.Rectangle;
RedactionAnnotation annot = new RedactionAnnotation(actualPage, new Rectangle(rect.LLX + 1.0, rect.LLY, rect.URX - 1.0, rect.URY))
{
FillColor = Aspose.Pdf.Color.Black,
};
actualPage.Annotations.Add(annot);
annot.Redact();
}
}
When I changed the regex to “(\d){4,5}( -{3}){2} -{4}” the TextFragment rectangle position is different from the previous one. What is the reason of this?
Sorry, I accidentally misspelled the second regex. What I wanted to write is (\d){4,5}([ -](\d){3}){2}[ -](\d){4}
So why can’t I redact the whole 10011 212-847-4915 and 35209 205-276-1807 matches when I searching with the (?:\d[ -]*){10,19} regex? But with the (\d){4,5}([ -](\d){3}){2}[ -](\d){4} I can.
I have worked with source file shared by you and shared my generated result with you as well. For further investigation can you please share comparison screenshot along with desired result.111outputsample_10.pdf (261.9 KB)