Free Support Forum - aspose.com

Search and highlight text in PDF using Aspose.PDF for .NET in C# - API is taking time

Hi,
I am using Aspose to search keyword in MS Office/ PDF/ txt files and highlighting the keyword. It properly search and highlights the keyword in the given file. Issue I am facing is the searching and highlighting takes time, is there any efficent way of searching an highlighting. I am sharing the code for PDF searching and highlighting:

Document doc = new Document(file);
TextFragmentAbsorber tfa = new TextFragmentAbsorber(searchkeyword.ToLower(), new TextSearchOptions(true));
 doc.Pages.Accept(tfa);
 TextFragmentCollection tfc = tfa.TextFragments;
 if (tfc.Count > 0)
 {
     foreach (TextFragment frag in tfc)
     {
         frag.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
         frag.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Yellow);
     }
}

@hashim129,

Thanks for contacting support.

Can you please share source PDF file with us so that we may further investigate to help you out.

Thank you for your response.
I am not talking about some specific file. It is generic issue I am facing when the file content is large like some PDF / word file of let say 50 or above pages and having many instances of the searched keyword. then it takes considerable amount of time.
My question is whether it is the only way to search and highlight or any other efficient way exists.

@hashim129,

I like to inform that you can split the Accept() call at page level as following to make the processing faster and share feedback with us.

foreach(Page page in pdfDocument.Pages)
{
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(searchText);
page.Accept(textFragmentAbsorber);
// Do some stuff
page.Dispose();
}