We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Highlight text in pdf

Hi,


I have a problem when Highlighting text in pdf only on title text.
I join you the result pdf page file.

Thank you

Here is the code :

Document pdfDocument = new Document(item);
//create TextAbsorber object to find all instances of the input search phrase
//TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(“Win”);
//TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("(?i)win", new TextSearchOptions(true));

//Loop through all the pages
foreach (Page pdfPage in pdfDocument.Pages)
{
//create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("(?i)hollande", new TextSearchOptions(true));
pdfPage.Accept(textFragmentAbsorber);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{

foreach (TextSegment textSegment in textFragment.Segments)
{
Find = true;
//Console.WriteLine("Text : {0} ", textSegment.Text);
//Console.WriteLine("Position : {0} ", textSegment.Position);
//Console.WriteLine("XIndent : {0} ", textSegment.Position.XIndent);
//Console.WriteLine("YIndent : {0} ", textSegment.Position.YIndent);
//Console.WriteLine(“Font - Name : {0}”, textSegment.TextState.Font.FontName);
//Console.WriteLine("Font - IsAccessible : {0} ", textSegment.TextState.Font.IsAccessible);
//Console.WriteLine("Font - IsEmbedded : {0} ", textSegment.TextState.Font.IsEmbedded);
//Console.WriteLine("Font - IsSubset : {0} ", textSegment.TextState.Font.IsSubset);
//Console.WriteLine("Font Size : {0} ", textSegment.TextState.FontSize);
//Console.WriteLine("Foreground Color : {0} ", textSegment.TextState.ForegroundColor);
//textSegment.TextState.ForegroundColor = Color.Black;
textSegment.TextState.BackgroundColor = Color.Yellow;

}
}

}

Hi Nicolas,


Thanks for your inquiry. Please note for highlighting a specific occurrence, you should now the particular index and replace/modify it accordingly. Please check documentation link to replace first occurrence only, hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,