title: iText 7 table with border bottom on last row of each page
body: <p>I am using iText 7 for creating a table inside the PDF file.
  My table must have only vertical border (left and right of each column) and in the first row of each page also topo border
  and in the last row of each page also bottom border.</p>
  <p>In each row there's only one columns that can be &quot;rowspanned&quot; on two lines (at max).</p>
  <p>I have successfully created the table with repeated header on each page but in the last row of each page i can't draw the bottom border.</p>
  <p>Problem can be approached in several ways.</p>
  <p>I use a function GetCell to obtain a cell object and then add to table like this</p>
  <pre><code>     var stream = new MemoryStream();
       var writer = new PdfWriter(stream);
       var pdf = new PdfDocument(writer);
       pdf.SetDefaultPageSize(PageSize.A4.Rotate());
       var document = new Document(pdf);
       iText.Layout.Element.Table table;
  
       ...HEADER
  
       table.AddHeaderCell(GetCell(1, 1, &quot;V&quot;, dgv.Columns[i].HeaderText, &quot;{0}&quot;, TextAlignment.CENTER, VerticalAlignment.TOP));
       ....AddHeaderCell for all columns
  
       ....init cycle
     
       table.AddCell(GetCell(1, 1, &quot;F&quot;, mystring, TextAlignment.CENTER, VerticalAlignment.TOP).SetBorder(null));
       ...ending cycle
       document.Add(table);
       document.close;
       .....
  </code></pre>
  <p>and then iterate through all cells in table and applied left and right border to cells.</p>
  <pre><code>int numrows= table.GetNumberOfRows();
  int numcols= table.GetNumberOfColumns();
  for (int irow = 0; irow &lt; numrows; irow++)
  {
      for (int icol = 0; icol &lt; numcols; icol++)
          {
          try 
              {
              Cell mycell = table.GetCell(irow,icol);
                  mycell.SetBorderRight(new SolidBorder(0.5f));
                  mycell.SetBorderLeft(new SolidBorder(0.5f));
              }
          catch (NullReferenceException)
              {
              }
          }
  }
  </code></pre>
  <p>The biggest difficulty  is knowing if the line i'm writing is the last one on the page and another difficult is getting the cell value during the iterative cycle.</p>
  <p>Considerations:</p>
  <p>I can apply bottom border also in GetCell function  in this case i should know in this phase if my row is the last in the page. I've tried with this but the result in not good
  After cell adding i verify if there's enough space to write another row.</p>
  <pre><code>LayoutResult result = table.CreateRendererSubTree().SetParent(document.GetRenderer()).Layout(
      new LayoutContext(new LayoutArea(1, new Rectangle(0, 0, 400, 1e4f))));
  
  LayoutArea currentArea = document.GetRenderer().GetCurrentArea();
  Rectangle rectangle = currentArea.GetBBox();
  float verticalPosition = rectangle.GetHeight();
  float docBottom = rectangle.GetBottom();
  
  
  float TableHeight = result.GetOccupiedArea().GetBBox().GetHeight();
  
  if (verticalPosition - TableHeight &lt;= docBottom)
  {
      // document.Add(new AreaBreak(AreaBreakType.NEXT_PAGE));
      //Debug.Print(&quot;........................................Last Row splitted&quot;);
  };
  
  
  private static Cell GetCell(int cm, int rowspan, string ItsHeader, string mytext, TextAlignment mytextalign,
      VerticalAlignment myvertalign) {
      Cell cell = new Cell(rowspan, cm);
      Paragraph p;
      if (ItsHeader == &quot;V&quot;) {
          cell.SetBackgroundColor(iText.Kernel.Colors.ColorConstants.LIGHT_GRAY);
          cell.SetTextAlignment(mytextalign);
          p = new Paragraph(String.Format(&quot;{0}&quot;, mytext)).SetFontSize(10);
          cell.Add(p);
      } else {
          if (myvertalign == VerticalAlignment.MIDDLE) {
              Div d = new Div();
              d.SetVerticalAlignment(VerticalAlignment.MIDDLE);
              p = new Paragraph(String.Format(&quot;{0}&quot;, mytext)).SetFontSize(8);
              p.SetTextAlignment(mytextalign);
              d.Add(p);
              cell.Add(d);
          } else {
              cell.SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE);
              p = new Paragraph(String.Format(&quot;{0}&quot;, mytext)).SetFontSize(8);
              p.SetTextAlignment(mytextalign);
              p.SetMultipliedLeading(1.5f);
              p.SetMarginTop(0);
              cell.Add(p);
          }
      }
  
      return cell;
  }
  </code></pre>
  <p>Thanks for your time and suggestions.</p>
  <p>I would obtain something like this
  <a href="https://i.stack.imgur.com/MF439.png" rel="nofollow noreferrer">Example</a></p>