PdfPTable table = new PdfPTable(numberOfColumns); table.setKeepTogether(false);
PdfPTable table; // your table table.setKeepTogether(false); // allows table to split table table.setHeaderRows(1); // rows of header table.setFooterRows(2); // rows of footer
/** * <p> * Creates a table. Specify the columns and widths by providing one<br> * float per column with a percentage value. For instance * </p> * <p> * <p> * getPdfPTable( 0.35f, 0.65f ) * </p> * <p> * <p> * will give you a table with two columns where the first covers 35 %<br> * of the page while the second covers 65 %. * </p> * * @param keepTogether Indicates whether the table could be broken across * multiple pages or should be kept at one page. * @param columnWidths The column widths. * @return */ public static PdfPTable getPdfPTable( boolean keepTogether, float... columnWidths ) { PdfPTable table = new PdfPTable( columnWidths ); table.setWidthPercentage( 100f ); table.setKeepTogether( keepTogether ); return table; }
Paragraph p = new Paragraph("Test"); PdfPTable table = new PdfPTable(2); for (int i = 1; i < 6; i++) { table.addCell("key " + i); table.addCell("value " + i); } for (int i = 0; i < 40; i++) { document.add(p); } // Try to keep the table on 1 page table.setKeepTogether(true); document.add(table);
pageTable.setKeepTogether(true); pageTable.setWidthPercentage(100f); outlineTable.setKeepTogether(true); outlineTable.setWidthPercentage(100f);
headerRow.setKeepTogether(true); headerRow.addCell("Date"); headerRow.addCell("Event"); firstRow.setKeepTogether(true); firstRow.addCell("date 1"); firstRow.addCell("event 2 1"); secondRow.setKeepTogether(true); PdfPCell cell = new PdfPCell(new Phrase("date 2")); cell.setRowspan(2);
pdfptable.setHeaderRows(lastHeaderRow + 1); pdfptable.setSplitLate(cellsFitPage); pdfptable.setKeepTogether(tableFitsPage); if (!Float.isNaN(offset)) { pdfptable.setSpacingBefore(offset);
pdfptable.setHeaderRows(lastHeaderRow + 1); pdfptable.setSplitLate(cellsFitPage); pdfptable.setKeepTogether(tableFitsPage); if (!Float.isNaN(offset)) { pdfptable.setSpacingBefore(offset);
pdfptable.setHeaderRows(lastHeaderRow + 1); pdfptable.setSplitLate(cellsFitPage); pdfptable.setKeepTogether(tableFitsPage); if (!Float.isNaN(offset)) { pdfptable.setSpacingBefore(offset);
table.addCell(inputCell); table.addCell(outputCell); table.setKeepTogether(true); document.add(table);
table.setKeepTogether( false ); table.setSpacingAfter( spacing );
if (keepTogether != null) table.setKeepTogether(keepTogether);