Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I use the last version of itextsharp.

I use the property HeaderRows=1 so that if there is a pagebreak, the Header rows will appear again in the next page.

Then we have the rows of the content with the border style without bottomline like this:

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

When there is a pagebreak, the line bottom of the table is not shown, which is not logical. Even if the content rows have no bottom / top border, the PdfPTable itself should have borders (it does not have in the code in fact).

Any ideas? Thx.

like image 972
netadictos Avatar asked Jun 22 '11 09:06

netadictos


1 Answers

I think I have been lucky, this was not easy to find.

I was looking for some event to localise the last row of the page and I found it.

You instance it like this:

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

The class is the following:

 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
}
like image 73
netadictos Avatar answered Nov 05 '22 08:11

netadictos