Hi Team,
Exception message logged is "Object reference not set to an instance of an object."
Hi Navaneethan,
Hi Team,
Hi Navaneethan,
Hi Navaneethan,
We have further investigated the issue and found that your issue has been fixed in recent release of Aspose.Pdf for .NET i.e. 11.6.0 in result of other related fix. You need to use Aspose.Pdf for .NET 11.6.0 and amend your above shared code as following, add annotation object to Page first and redact it later. Because redact method try to flatten the annotation, so API throws exception if it is not available in the Page resources at that time.
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(myDir + "testContent.pdf");
foreach (string keyword in keywords)
{
TextFragmentCollection textFragmentCollection = SearchPDF(doc, "Accenture");
// Loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
// Create RedactionAnnotation instance for specific page region
Aspose.Pdf.Annotations.RedactionAnnotation annot =
new Aspose.Pdf.Annotations.RedactionAnnotation(doc.Pages[textFragment.Page.Number], textFragment.Rectangle);
annot.FillColor = Aspose.Pdf.Color.Black;
annot.BorderColor = Aspose.Pdf.Color.Yellow;
annot.Color = Aspose.Pdf.Color.Blue;
// Text to be printed on redact annotation
// annot.OverlayText = "REDACTED";
annot.TextAlignment = Aspose.Pdf.HorizontalAlignment.Center;
annot.Repeat = true; // Repeat overlay text over redact annotation
// Add annotation to annotations collection of the respective page
doc.Pages[textFragment.Page.Number].Annotations.Add(annot);
// Flatten annotation and redact page contents (removes text and image under the redacted annotation)
annot.Redact();
}
}
doc.Save(myDir + "AnnotationOutput.pdf");
Please feel free to contact us for any further assistance.
Best Regards,
The issues you have found earlier (filed as PDFNET-40512) have been fixed in Aspose.PDF for .NET 23.4.