title: iText7 and C#, put a filled shape in a table cell
body: <p>I am trying to add a rectangle with rounded borders in a cell of a table, created with iText7 and C#.</p>
  
  <p>I tried using</p>
  
  <p><code>table.AddCell(new Cell().Add(rect)</code></p>
  
  <p>where i created <code>rect</code> with</p>
  
  <pre><code>Rectangle boundingBox = new Rectangle(20, 470, 30, 30);
  PdfFormXObject xObject = new PdfFormXObject(boundingBox);
  xObject.MakeIndirect(pdfDoc); //Make sure the XObject gets added to the document
  PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());
  Color greenColor = new DeviceCmyk(100, 30, 100, 0);
  canvas.SetFillColor(greenColor);
  canvas.Rectangle(294, 780, 50, 35);
  canvas.FillStroke();
  
  Image rect = new Image(xObject);
  </code></pre>
  
  <p>suggested from a friend of mine, but I think this is the wrong way to do this, and I'm not even quite sure of what this code does. Plus, the rectangle is transparent, has big margins, and the font in the cells is now green too (it was black before inserting the rectangle).</p>
  
  <p>Here is how it looks like (i purposedly put the square a little bit higher to show the transparency):</p>
  
  <p><a href="https://i.stack.imgur.com/yRHO7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yRHO7.png" alt="enter image description here"></a></p>
  
  <p>What I want to do is to create a green shape rectangle, round the borders, then put it in the cell.</p>
  
  <p>It should look like this:</p>
  
  <p><a href="https://i.stack.imgur.com/mPu1l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mPu1l.png" alt="enter image description here"></a></p>
  
  <p>Is there a good way to do that?</p>