2011-06-22 24 views
6

我使用itextsharp的最新版本。itextsharp:如何顯示具有屬性的表的底線HeaderRows = 1如果行的邊界底部沒有設置?

我使用屬性HeaderRows = 1,這樣如果有分頁符,標題行將再次出現在下一頁。

然後我們有邊框樣式內容的行,而不底線是這樣的:

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

當有分頁符,表的線路的底部沒有顯示,這是不符合邏輯的。 即使內容行沒有底部/頂部邊框,PdfPTable本身也應該有邊框(實際上它沒有在代碼中)。

任何想法?謝謝。

回答

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 
} 
相關問題