TextFragmentAbsorber Failing To Find Text on Last Page

The following code is finding and replacing text on pages inside the PDF, but failing to find matching text on the last page of the PDF.

var textFinder = new TextFragmentAbsorber(matchString);
_document.Pages.Accept(textFinder);
TextFragmentCollection collector = textFinder.TextFragments;
foreach (TextFragment match in collector) {
    match.Text = replaceString;
}

@lancomkaleb

Thank you for contacting support.

Would you please share sample PDF document and SSCCE code so that we may try to reproduce and investigate it in our environment. Before sharing requested data, please ensure using Aspose.PDF for .NET 19.1.

Attached is the pdf before and after running this find and replace code using Aspose

public void AsposeBug(string filepath) {
    var document = new Aspose.Pdf.Document(filepath);
    var matchString = "<#document_owner>";
    var replaceString = "John Doe";

    var textFinder = new TextFragmentAbsorber(matchString);
    document.Pages.Accept(textFinder);
    TextFragmentCollection collector = textFinder.TextFragments;

    foreach (TextFragment match in collector) {
        match.Text = replaceString;
    }

    document.Save(filepath); // Overwrite
}

There are two “<#document_owner>” strings in the pdf, but only one gets replaced. If I remove the first instance of “<#document_owner>” it still does not replace the string on the last page.

aspose-post-replace.pdf (272.9 KB)
aspose-pre-replace.pdf (221.8 KB)

@lancomkaleb

Thank you for sharing requested data.

You are currently facing evaluation limitation which allows to process only four items from any collection, along with evaluation watermark, as explained in Licensing. The text is replaced fine with licensed version of the API. We have attached generated PDF file for your kind reference aspose-post-replace_19.1.pdf.

You can test the API in its full capacity by applying a 30-days temporary license. You may apply for free temporary license on the given link and evaluate latest version of the API as per your requirements.