Free Support Forum - aspose.com

Call to Aspose.Pdf.Document.Pages.Accept with REGEX ".*" does not return

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.
        pdfDocument.Pages.Accept(textFragmentAbsorber);

        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;
        }

        pdfDocument.Save(txtDestination.Text);
    }

texttopdf.pdf (47.8 KB)

-Nell

@taninf,

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 20.1.0.0 and I cannot replicate the said issue. The version that I have the issue with is 10.9.0.0.

Thank you very much!

Nell

@taninf

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