开发者

Drawing a horizontal line to the table at the end of page in iText?

I m creating a table using iText. Each table has 2 columns and have no borders except for left most, right most, top most and bottom most side of the table. I am able to achieve this but the problem occurs when new page begins. I want the to draw a horizontal line to the table at the end of page and another horizontal line when it begins. I have tried using

@Override
public void onEndPage(PdfWriter arg0, Document arg1) {
    PdfPCell pdfpcells[] = pdfptable.getRow(pdfptable.getRows().size()-1).getCells();
    pdfpcells[0].setBorderWidthBottom(0.5f);
    if(pdfpcells[1] != null){ //There is a possibility that there are odd number of el开发者_开发知识库ements
       pdfpcells[1].setBorderWidthBottom(0.5f);
    }
}

for drawing horizontal line at the end of page assuming this function is called every time page ends and hence uses current number of rows. pdfptable is declared as class variable. This doesn't seem to work. I am using latest version of iText. Thanks.


Can you post the code that constructs the table? Do you make one per page or are you relying on the auto-split of the PdfPTable?

The code below should do the trick:

 PdfPCell pdfPCells[] = table.getRow(table.getRows().size() - 1).getCells();
 for (PdfPCell pdfPCell : pdfPCells) {
     pdfPCell.setBorder(PdfPCell.BOTTOM);
 }

As you can see there is no need for you to worry about the number of elements in the array, if you just use a for-each loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜