var inputFile = Path.Combine(dataDir, "input.pdf");
var outputFile = Path.Combine(dataDir, "output.pdf");
var pdfDocument = new Aspose.Pdf.Document(inputFile);
var searchTerm = "Secret";
var textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber(searchTerm);
var textSearchOptions = new Aspose.Pdf.Text.TextSearchOptions(true);
textFragmentAbsorber.TextSearchOptions = textSearchOptions;
pdfDocument.Pages.Accept(textFragmentAbsorber);
var textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach (var textFragment in textFragmentCollection)
{
var page = textFragment.Page;
var annotationRectangle = textFragment.Rectangle;
var annot = new Aspose.Pdf.Annotations.RedactionAnnotation(page, annotationRectangle)
{
FillColor = Aspose.Pdf.Color.Black
};
pdfDocument.Pages[textFragment.Page.Number].Annotations.Add(annot, true);
annot.Redact();
}
pdfDocument.Save(outputFile);