Exception" Out Of Memory" while searching text in PDF (C#)

Hi guys,

I need help using a regex to search on a pdf file. A call to pdfDocument.Pages.Accept(textFragmentAbsorber); does not return until it gets outofmemory exception. I have .* for my regex to query all the contents of a text file converted to pdf. I have attached the source pdf.

Please help me understand what’s wrong with my code. I appreciate you all!!!

    private void btnSearch_Click(object sender, EventArgs e)
        Document pdfDocument = new Document(txtSource.Text);
        TextSearchOptions textSearchOptions = new TextSearchOptions(true);
        TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(".*", textSearchOptions);

        //This call to "Accept" is not returning until it would get an outofmemory exception.

        TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

        foreach (TextFragment textFragment in textFragmentCollection)
            textFragment.Text = "<MODIFIEDTEXT>";
            textFragment.TextState.Font = FontRepository.FindFont("Verdana");
            textFragment.TextState.FontSize = 22;
            textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
            textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.Green;


texttopdf.pdf (47.8 KB)



I have worked with source file and sample code shared by you using Aspose.PDF 20.1 and unable to observe the issue. I have also shared my generated result with you for your kind reference. Can you please try to use Aspose.PDF latest version.outpdf.pdf (121.5 KB)

Hello Adnan,

I appreciate the quick response to my queries. I just tried the latest version and I cannot replicate the said issue. The version that I have the issue with is

Thank you very much!



Thanks for your kind feedback.

We would like to inform you that support is provided on the basis of latest version of the API and we request you to upgrade to latest version in order to get correct results at your side.

1 Like