Itextsharp: how to show the bottom row of a table with the HeaderRows = 1 property if the bottom row boundary is not set?

I am using the latest version of itextsharp.

I use the HeaderRows = 1 property, so if there is a page break, the header lines will appear again on the next page.

Then we have content lines with a border style without a bottom line, like this:

PdfPCell cell1 = null; cell1 = new PdfPCell(new Phrase(string.Format("{0}", c1), fn)); cell1.Border = Rectangle.RIGHT_BORDER | Rectangle.LEFT_BORDER; 

When a page break occurs, the bottom row of the table is not displayed, which is not logical. Even if the content lines do not have a lower / upper border, the PdfPTable itself should have borders (in fact, there is none).

Any ideas? thanks.

+6
source share
1 answer

I think I was lucky, it was not easy to find.

I was looking for some kind of event to localize the last line of the page, and I found it.

You repeat it like this:

  PdfPTable ItemTable = new PdfPTable(7); ItemTable.TableEvent = new LineaBottom(); 

The class is as follows:

  public class LineaBottom : IPdfPTableEvent { #region IPdfPTableEvent Members void IPdfPTableEvent.TableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { int columns; Rectangle rect; int footer = widths.Length - table.FooterRows; int header = table.HeaderRows - table.FooterRows + 1; int ultima = footer - 1; if (ultima != -1) { columns = widths[ultima].Length - 1; rect = new Rectangle(widths[ultima][0], heights[ultima], widths[footer - 1][columns], heights[ultima + 1]); rect.BorderColor = BaseColor.BLACK; rect.BorderWidth = 1; rect.Border = Rectangle.TOP_BORDER; canvases[PdfPTable.BASECANVAS].Rectangle(rect); } } #endregion } 
+5
source

Source: https://habr.com/ru/post/891096/


All Articles