title: iTextSharp - Unable to draw rectangle over tablecell background color
body: <p>I'm using iTextSharp to create a PDF using an HTML page as an example. I am trying to put a border around text to highlight certain items. Using methods from these posts (<a href="https://stackoverflow.com/a/24008380/3178854">Draw Rect at curr position</a>, and <a href="https://stackoverflow.com/a/28067028/3178854">Add Text over image</a>  ) I have used OnGenericTag events to create the rectangle for each Chunk that matches certain criteria. The event fires correctly and the rectangles are drawn on the correct elements. However the problem occurs when I add the background for the tablecell, it appears on top of the Chunk rectangles. Is there a way to make the rectangle drawn from the <code>OnGenericTag</code> event drawn above the table cell background?</p>
  
  <hr>
  
  <p>OnGenericTags Method:</p>
  
  <pre><code>public class GenericTags : PdfPageEventHelper
      {
          public override void OnGenericTag(PdfWriter writer, Document pdfDocument, iTextSharp.text.Rectangle rect, String text)
          {
              if ("ellipse".Equals(text)) //I know it's not needed. 
                  ellipse(writer.DirectContent, rect);
          }
  
          public void ellipse(PdfContentByte content, iTextSharp.text.Rectangle rect)
          {
              content.SaveState();
              content.SetRGBColorStroke(0x00, 0x00, 0xFF);
              content.SetLineWidth(2);
              content.Rectangle(rect.Left - 2f, rect.Bottom - 3f, rect.Width, rect.Height + 3f);
              content.Stroke();
              content.RestoreState();
          }
      }
  </code></pre>
  
  <hr>
  
  <p>Each <code>PdfPCell</code> is defined as: </p>
  
  <pre><code>PdfPCell med = new PdfPCell(ph[4])
     {
       HorizontalAlignment = Element.ALIGN_CENTER,
       VerticalAlignment = Element.ALIGN_CENTER,
       BackgroundColor = hm_yellow //this draws above rect from onGenericTag()
     };
  </code></pre>
  
  <hr>
  
  <p>The <code>Chunks</code> are created and assign via a <code>foreach</code> loop:</p>
  
  <pre><code>ph[j] = new Phrase();
  foreach (var x in p.Risks)
     {
        c[i] = new Chunk("R" + x.APP_RISK_ID.ToString() + ", ");
        if (x.RISK_STATUS_CD == "57")
        {
          //c[i].SetBackground(hm_top_tier); // still shows behind table cell background
          c[i].SetGenericTag("ellipse");
        }
      ph[j].Add(c[i]);
     }
  </code></pre>
  
  <p>This is the HTML page I'm trying to turn into a PDF. It shows the table cell background colors and the values that need to have a rectangle around them to highlight them. 
  <img src="https://i.stack.imgur.com/TvWIr.png" alt="Heat map from HTML"></p>
  
  <p>This is the result when rendering a PDF. The highlighted R#'s match, however, when I apply a background color to the <code>PdfPCell</code> it is drawn over the rectangle from the <code>Chunk</code>
  <img src="https://i.stack.imgur.com/eMCi0.png" alt="heat map from pdf"></p>