I use the last version of itextsharp.
I u开发者_开发技巧se 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.
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
}
精彩评论