I have redacted the “document” word from the “sample.pdf”. The searchable text was removed correctly but the black redaction rectangles are in the wrong positions. It seems like it has been rotated with 90°. What could cause this?
Aspose.PDF .NET 20.3 version
Original file: sample.pdf (1.9 MB)
After redaction: ScreenshotFromOneOfThePage.png (208.0 KB)
Code snippet:
public void Redact()
{
foreach (Page actualPage in pdfDocument.Pages)
{
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("document");
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();
}
}
pdfDocument.Save("output.pdf");
}
Thanks,
Gabor