Draw Rectangle Behind Text

The following code draws a rectangle around the searched-for text.  But if I choose PdfBrushes.Red for the fill, it covers up the text completely. How do I modify this code such that the rectangle is behind the text instead of in front of it?

Dictionary<int, List<RectangleF>> matchText = null;
pdfViewerControl1.FindText(searchText, out matchText);

foreach (int page in matchText.Keys)
{
   foreach (RectangleF rect in matchText[page])
   {
       PdfGraphics graphics = doc.Pages[page].Graphics;
       graphics.DrawRectangle(PdfPens.Red, PdfBrushes.Transparent, rect);
   }
}

Thanks for any help.


1 Reply

MN Meikanda Nayanar Syncfusion Team February 20, 2014 07:07 AM UTC

Hi Chuck,

We have analyzed your requirement and found that we cannot fill the rectangle behind the text, but we can achieve this by setting the transparency of the graphics as in the below snippet.

graphics.SetTransparency(0.25f);

graphics.DrawRectangle(PdfBrushes.Red, rect);

graphics.SetTransparency(1.0f);

We have attached a simple sample on this for your reference below.

Please let us know if you need any further assistance.

Thanks,

Uthistran


Attachment: Sample_4c593e12.zip

Loader.
Up arrow icon