1

I know the coordinates of the text on the page. How can I set the background color for this text? Any help would be appreciated.

Boris_56
  • 27
  • 6
  • 2
    Does this answer your question? [how to highlight a text or word in a pdf file using iTextsharp?](https://stackoverflow.com/questions/6523243/how-to-highlight-a-text-or-word-in-a-pdf-file-using-itextsharp) – Sinatr Jul 07 '21 at 13:09
  • I made it much easier. I need to set a hyperlink to this text. It is enough to set the color of the border to this hyperlink, instead of the background color of the text, and this will give the user the necessary information. It would be great if you could paint over the entire area of the hyperlink, but most likely this is not possible. Another way is to overlay a rectangle on the text, paint it in the desired color, but so that the text is visible. And this opportunity is also most likely not. If you have any comments, write. – Boris_56 Jul 09 '21 at 10:55

1 Answers1

0

I sorted out. It is need to add PdfTextMarkupAnnotation to this area.Here is the code. Perhaps it will be useful to someone.

float[] quads = new float[8];
            quads[0] = rect.GetX();
            quads[1] = rect.GetY() + rect.GetHeight();
            quads[2] = rect.GetX() + rect.GetWidth();
            quads[3] = quads[1];
            quads[4] = quads[0];
            quads[5] = rect.GetY();
            quads[6] = quads[2];
            quads[7] = quads[5];
PdfTextMarkupAnnotation highlightAnnotation = 
      PdfTextMarkupAnnotation.CreateHighLight(rect, quads);
//установка цвета аннотации
highlightAnnotation.SetColor(ColorConstants.GREEN);
page.AddAnnotation(highlightAnnotation);
Boris_56
  • 27
  • 6