How to highlight the word from the given word in whole pdf

Hi sir,

  I need to highlight the text  from the given word from text box  in whole pdf and save in different pdf. this one i need very urgent pls reply asap.

Note : I need Highlight the text in whole pdf

@senthilnathan

Thank you for contacting support.

You can search and highlight text using below code snippet in your environment.

        Document document = new Document(dataDir + "Test.pdf");
        TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("SEARCH STRING");
        document.Pages.Accept(textFragmentAbsorber);
        TextFragmentCollection textFragmentCollection1 = textFragmentAbsorber.TextFragments;
        if (textFragmentCollection1.Count > 0)
        {
            foreach (TextFragment textFragment in textFragmentCollection1)
            {
                {
                    Aspose.Pdf.Annotations.HighlightAnnotation freeText = new Aspose.Pdf.Annotations.HighlightAnnotation(textFragment.Page, new Aspose.Pdf.Rectangle(textFragment.Position.XIndent, textFragment.Position.YIndent, textFragment.Position.XIndent + textFragment.Rectangle.Width, textFragment.Position.YIndent + textFragment.Rectangle.Height));
                    freeText.Color = Aspose.Pdf.Color.Red;
                    textFragment.Page.Annotations.Add(freeText);
                    freeText.Flatten();
                }
            }
        }
        document.Save(dataDir + "Test_18.5.pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Hi sir,
Thanks for reply the code i put the yellow color i mark it show the error. pls reply asap.
**image.png (16.7 KB)
**

@senthilnathan

We have observed the image shared by you and the problem looks as if Aspose.PDF for .NET API may not be referenced correctly. Please make sure that you install the API in your environment as the code is working perfectly fine in our environment. Fine.JPG

We hope this will be helpful. Please feel free to contact us if you need any further assistance.