Redaction issue --Urgent help required

Hi Team,

I am facing an issue in Search and redaction .I am using version 2.0 Aspose.pdf dll. It works fine in Local but when it is deployed in the server it is throwing an unknown exception while saving the pdf file into stream.Please help as soon as possible.My search keyword is “Accenture” and i have attached the file here.

Please find the below code
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(@"…\App_Data\Aspose.Pdf.lic");
string[] keywords = maskingBdo.Keywords.Split(’,’);

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(new MemoryStream(maskingBdo.FileContent));
#region

foreach (string keyword in keywords)
{
TextFragmentCollection textFragmentCollection = this.pdfSearchService.SearchPDF(doc, keyword);
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
// create RedactionAnnotation instance for specific page region
RedactionAnnotation annot = new Aspose.Pdf.InteractiveFeatures.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;
// repat Overlay text over redact Annotation
annot.Repeat = true;
// Flattens annotation and redacts page contents (i.e. removes text and image
// under redacted annotation)
annot.Redact();
// add annotation to annotations collection of first page
doc.Pages[textFragment.Page.Number].Annotations.Add(annot);

}
}

byte[] byteArrayObject;
using (var streamReader = new MemoryStream())
{
doc.Save(streamReader, SaveFormat.Pdf);
byteArrayObject = streamReader.ToArray();
}
return byteArrayObject;
#endregion


public dynamic SearchPDF(dynamic inputPdfDocument, string searchKeyword)
{
try
{
Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber(@"(?i)\b" + searchKeyword + @"\b");
//set text search option to specify regular expression usage
Aspose.Pdf.Text.TextOptions.TextSearchOptions textSearchOptions = new Aspose.Pdf.Text.TextOptions.TextSearchOptions(true);
textFragmentAbsorber.TextSearchOptions = textSearchOptions;
//accept the absorber for all the pages
inputPdfDocument.Pages.Accept(textFragmentAbsorber);
//get the extracted text fragments
return textFragmentAbsorber.TextFragments;
}
catch (Exception exception)
{
this.auditService.AuditLog(Convert.ToString(EventType.Error), “PDFSearchService.SearchPdf”, exception.StackTrace);
return null;
}
}

Thanks,
Navaneethan V

Exception message logged is "Object reference not set to an instance of an object."


and the exception stack trace shows as below
at ?.?.?a(?? , ? )
at ?.?.()
at ?.?.?()
at ?..??()
at Aspose.Pdf.Document.Convert(XmlTextWriter , PdfFormat , Boolean , ConvertErrorAction )
at Aspose.Pdf.Document.Save(Stream output)
at Accenture.Cio.PdfTool.PdfService.MaskService.MaskKeyword(IMaskingBdo maskingBdo)

Hi Navaneethan,


Thanks for using our API’s.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNEWNET-40512 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Hi Team,

Can you please update me on this issue?


Thanks,
Navaneethan V

Hi Navaneethan,


Thanks for your patience.

The earlier reported issue is pending for review and is not yet resolved. However the product team will surely consider investigating/fixing it as per development schedule and as soon as we have some definite updates regarding its resolution, we will let you know. Please be patient and spare us little time. We are sorry for this delay and inconvenience.

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”);<o:p></o:p>

//
foreach (string keyword in keywords)
<o:p></o:p>

{<o:p></o:p>

TextFragmentCollection textFragmentCollection =
SearchPDF(doc, “Accenture”);<o:p></o:p>

//loop through the fragments<o:p></o:p>

foreach (TextFragment
textFragment in textFragmentCollection)<o:p></o:p>

{<o:p></o:p>

// create
RedactionAnnotation instance for specific page region
<o:p></o:p>


Aspose.Pdf.Annotations.RedactionAnnotation
annot = new Aspose.Pdf.Annotations.RedactionAnnotation(doc.Pages[textFragment.Page.Number],
textFragment.Rectangle);<o:p></o:p>


annot.FillColor = Aspose.Pdf.Color.Black;<o:p></o:p>


annot.BorderColor = Aspose.Pdf.Color.Yellow;<o:p></o:p>


annot.Color = Aspose.Pdf.Color.Blue;<o:p></o:p>

// text to be printed on redact annotation<o:p></o:p>

// annot.OverlayText = “REDACTED”;<o:p></o:p>


annot.TextAlignment = Aspose.Pdf.HorizontalAlignment.Center;<o:p></o:p>

// repat Overlay text over redact Annotation<o:p></o:p>


annot.Repeat = true;<o:p></o:p>

// add annotation to annotations collection of first page<o:p></o:p>


doc.Pages[textFragment.Page.Number].Annotations.Add(annot);<o:p></o:p>

// Flattens annotation and redacts page contents (i.e.
removes text and image
<o:p></o:p>

// under redacted annotation)<o:p></o:p>


annot.Redact();
<o:p></o:p>


<o:p></o:p>

}<o:p></o:p>

}<o:p></o:p>

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.