How to prevent the publication of an iText PdfPCell spreadsheet spanning multiple pages from pagination?

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

The first column of the table spans several rows. Depending on the previous content, the column is sometimes split into two pages. Sometimes only one line remains on the first page, leaving the column not high enough to display the label.

Is there a way to determine if a column will span two pages if it is added to the document, so I can fill in some lines to prevent this behavior.

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

+4
source share
1 answer

Well, I encoded 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 this works very well, as Kornelije asked ... "Invalid" output will only be generated when I use table.setSplitLate(false) , so with the default value true everything is just fine.

0
source

All Articles