开发者

How to prevent iText table PdfPCell spanning across multiple rows from splitting across pages?

开发者 https://www.devze.com 2023-03-24 16:50 出处:网络
I am using iText (iTextSharp 5.1.1) and I am trying to do some tables. The first table column spans across several rows. Depending on previous content, the column would sometimes be split on two page

I am using iText (iTextSharp 5.1.1) and I am trying to do some tables.

The first table column spans across several rows. Depending on previous content, the column would sometimes be split on two pages. Sometimes, only one row would remain on the first page, leaving the column not high enough for a label to be displayed.

Is there any way to detect if a column would span across two pages if added to a document, so I can fill 开发者_如何学Cin some rows to prevent this behavior.

Or is there a way to tell a cell not to split under any circumstances?


Well, I coded your example with iText 2.1.7 in Java:

PdfPTable table = new PdfPTable(2);
table.setSplitLate(true); // default value
PdfPCell largeCell =
        new PdfPCell(new Paragraph("Lorem ipsum dolor sit amet,\r\n"
                + "consectetur adipiscing elit. Curabitur\r\n"
                + "vel nisl quis turpis molestie blandit.\r\n"
                + "Donec a ligula sit amet quam feugiat\r\n"
                + "aliquet in id augue. Etiam placerat\r\n"
                + "massa ac ligula dictum convallis.\r\n"
                + "Mauris in leo quis lorem facilisis\r\n"
                + "tincidunt. Praesent lorem libero,\r\n"
                + "porttitor tincidunt egestas consequat,\r\n"
                + "tempor quis erat. Sed lorem ipsum,\r\n"
                + "posuere a ornare ac, viverra ut diam. In\r\n"
                + "porta ultrices tristique. Nulla non libero\r\n"
                + "a nisi pharetra consequat. Vestibulum\r\n"
                + "nunc urna, lobortis id ultricies vitae,\r\n"
                + "fermentum eu magna. Duis nibh lacus,\r\n"
                + "adipiscing at tempor eget, interdum\r\n" + "quis libero."));

PdfPCell cell = new PdfPCell(new Paragraph("Long Column"));
cell.setRowspan(5);
table.addCell(cell);
for (int i = 0; i < 5; i++)
{
    table.addCell(largeCell);
}

And it works quite well as asked by Kornelije... The "wrong" output will only be produced, when I use table.setSplitLate(false), so with the default value of true everything is just fine.

0

精彩评论

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