Add bold text to highlight annotation

I want to add bold content in highlight annotaion, Please refer the code below and refer img,

HighlightAnnotation ha1 = new HighlightAnnotation(page, AdjustToolTip ? new Rectangle(textFragment.Segments[1].Rectangle.LLX + extraVal, textFragment.Segments[1].Rectangle.LLY, textFragment.Segments[1].Rectangle.URX + extraVal, textFragment.Segments[1].Rectangle.URY) : textFragment.Segments[1].Rectangle);

            ha1.Color = color;
            ha1.Modified = DateTime.Now;
            ha1.Contents = "Highlighted **<strong>bold</strong>** text";
            ha1.Flags = AnnotationFlags.ToggleNoView;               
            return ha1;

Capture.PNG (107.1 KB)

@ansaridurai
The following will work

HighlightAnnotation highlight = new HighlightAnnotation(textFragment.Page, rect);
highlight.Opacity = (.80);
highlight.Border = (new Border(highlight));
highlight.Color = (Color.LightBlue);
highlight.RichText = highlight.RichText = "<p dir=\"ltr\" style=\"margin-top:0pt;margin-bottom:0pt;font-family:Helvetica;font-size:12pt;\">Highlighted <span style=\"font-weight:bold\">bold</span> text</p>";
textFragment.Page.Annotations.Add(highlight);

image_2024_07_16T12_37_17_854Z.png (51.3 KB)

Yes its working. Thanks a lot!

1 Like