itextsharp:如果没有设置行的边框底部,如何显示具有属性HeaderRows = 1的表的底线?

时间:2011-06-22 09:46:04

标签: c# .net itextsharp

我使用了最后一个版本的itextsharp。

我使用属性HeaderRows = 1,这样如果有分页符,则页眉行将再次出现在下一页中。

然后我们得到内容的行,边框样式没有底线,如下所示:

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

如果有分页符,则不会显示表格的行底部,这不符合逻辑。 即使内容行没有底部/顶部边框,PdfPTable本身也应该有边框(事实上它在代码中没有)。

有什么想法吗? THX。

1 个答案:

答案 0 :(得分:5)

我想我很幸运,这不容易找到。

我正在寻找一些事件来本地化页面的最后一行,我发现了它。

你这样实例:

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

该课程如下:

 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
}