HighlightAnnotation in pdf is not accurate

hi to all

i use highlight annotation to highlight some text in pdf but is not accurate on the big text going a little bit up i’ll attach file pdf for example
wwwmetronewsit190107sanitC3A0garofalohcsaleoltre83casacuranobilihtmlGAROFALOHEALTHCAREWEB.pdf (184.6 KB)
wwwmetronewsit190107sanitC3A0garofalohcsaleoltre83casacuranobilihtmlGAROFALOHEALTHCAREWEB.pdf

@francescoes

Thanks for contacting support.

Could you please share respective source PDF document along with sample code snippet. We will test the scenario in our environment and address it accordingly.

here you are sample code :

Dim licence As Aspose.Pdf.License = New Aspose.Pdf.License
licence.SetLicense(Application.StartupPath + “\lib\Aspose.Pdf.lic”)

        'Preprocessing keywords
        KeyWord = KeyWord.Trim()
        KeyWord = KeyWord.Replace("(?i) ", "(?i)")
        KeyWord = KeyWord.Replace(" |", "|")
        KeyWord = KeyWord.Replace(" ", "\s+")
        KeyWord = KeyWord.Replace("(?i)", "\b(?i)")
        KeyWord = KeyWord.Replace("|", "\b|")
        KeyWord = KeyWord + "\b"

        Dim Document As New Document(PathPDFSource)

        Dim TextFragmentAbsorber As New TextFragmentAbsorber(KeyWord)

        'Set text search option to specify regular expression usage
        Dim TextSearchOptions As New TextSearchOptions(True)

        TextFragmentAbsorber.TextSearchOptions = TextSearchOptions

        Document.Pages.Accept(TextFragmentAbsorber)

        Dim TextFragmentCollection1 As TextFragmentCollection = TextFragmentAbsorber.TextFragments
        If TextFragmentCollection1.Count > 0 Then
            Dim Objxml As New ClsXml
            Objxml.CreateFileXml(System.IO.Path.GetFileNameWithoutExtension(PathPDFSource))
            For Each TextFragment As TextFragment In TextFragmentCollection1

                'SCRITTURA DEL FILE XML PER L'EVIDENZIAZIONE ARTICOLO
                Dim FreeText As New 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))
                Objxml.createNode(TextFragment.Page.Number.ToString, TextFragment.Position.XIndent.ToString, TextFragment.Position.YIndent.ToString, (TextFragment.Position.XIndent + TextFragment.Rectangle.Width).ToString, (TextFragment.Position.YIndent + TextFragment.Rectangle.Height).ToString)

                FreeText.Opacity = 0.9
                FreeText.Color = Aspose.Pdf.Color.FromArgb(255, 255, 0)

                TextFragment.Page.Annotations.Add(FreeText)
            Next
            Objxml.closeFileXml()
        End If

        Document.Save(PathPDFSource)

@francescoes

Thanks for sharing sample code snippet.

Would you please share your input PDF document with us. This would help us testing the scenario accordingly.

here you are , thank you
wwwmetronewsit190107sanitC3A0garofalohcsaleoltre83casacuranobilihtmlGAROFALOHEALTHCAREWEB.pdf (189.1 KB)

@francescoes

Thanks for providing sample PDF document.

We have tested the scenario using following code snippet with Aspose.PDF for .NET 19.1 and were unable to replicate the issue you have mentioned. For your kind reference, an output PDF is also attached.
[C#]

Document document = new Document(dataDir + "SampleForHighlighting.pdf");
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(@"(?i)Garofalo(?i)");
TextSearchOptions textSearchOptions = new TextSearchOptions(true);
textFragmentAbsorber.TextSearchOptions = textSearchOptions;
document.Pages.Accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection1 = textFragmentAbsorber.TextFragments;
if (textFragmentCollection1.Count > 0)
{
 foreach (TextFragment textFragment in textFragmentCollection1)
 {
  Aspose.Pdf.Annotations.HighlightAnnotation highlightText = 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));
 highlightText.Opacity = 0.5;
 highlightText.Color = Aspose.Pdf.Color.Yellow;
 textFragment.Page.Annotations.Add(highlightText);
 }
}

SampleForHighlighting_out.pdf (197.0 KB)

Would you please try using latest version of the API and in case you still face any issue, please feel free to let us know.