class RepeatSplitEvent extends PdfPTableEventForwarder { @Override public void afterSplitTable(PdfPTable table, PdfPRow startRow, int startIdx) { for (int i = startIdx - 5; i < startIdx; i++) { table.getRows().add(0, table.getRow(i)); } } }
/** * Defines which rows should not allow a page break (if possible). * * @param rows int[] * @throws java.lang.IndexOutOfBoundsException if a row index is passed that * is out of bounds */ public void keepRowsTogether(int[] rows) { for (int i = 0; i < rows.length; i++) { getRow(rows[i]).setMayNotBreak(true); } }
/** * Defines which rows should not allow a page break (if possible). * * @param rows int[] * @throws java.lang.IndexOutOfBoundsException if a row index is passed that * is out of bounds */ public void keepRowsTogether(int[] rows) { for (int i = 0; i < rows.length; i++) { getRow(rows[i]).setMayNotBreak(true); } }
/** * Correct chosen last fitting row so that the content of all cells with * open rowspans will fit on the page, i.e. the cell content won't be * split. (Only to be used with splitLate == true) */ public void correctLastRowChosen(PdfPTable table, int k) { PdfPRow row = table.getRow(k); Float value = correctedHeightsForLastRow.get(k); if (value != null) { row.setFinalMaxHeights(value); //System.out.printf("corrected chosen last fitting row: %6.0f\n\n", row.getMaxHeights()); } } }
/** * Correct chosen last fitting row so that the content of all cells with * open rowspans will fit on the page, i.e. the cell content won't be * split. (Only to be used with splitLate == true) */ public void correctLastRowChosen(PdfPTable table, int k) { PdfPRow row = table.getRow(k); Float value = correctedHeightsForLastRow.get(k); if (value != null) { row.setFinalMaxHeights(value); //System.out.printf("corrected chosen last fitting row: %6.0f\n\n", row.getMaxHeights()); } } }
/** * Gets row index where cell overlapping (rowIdx, colIdx) starts * * @param rowIdx * @param colIdx * @return row index * @since iText 5.4.3 */ public int getCellStartRowIndex(int rowIdx, int colIdx) { int lastRow = rowIdx; while (getRow(lastRow).getCells()[colIdx] == null && lastRow > 0) { --lastRow; } return lastRow; }
/** * Gets row index where cell overlapping (rowIdx, colIdx) starts * * @param rowIdx * @param colIdx * @return row index * @since iText 5.4.3 */ public int getCellStartRowIndex(int rowIdx, int colIdx) { int lastRow = rowIdx; while (getRow(lastRow).getCells()[colIdx] == null && lastRow > 0) { --lastRow; } return lastRow; }
/** * Defines a range of rows that should not allow a page break (if possible). * * @param start int * @param end int * @throws java.lang.IndexOutOfBoundsException if a row index is passed that * is out of bounds */ public void keepRowsTogether(int start, int end) { if (start < end) { while (start < end) { getRow(start).setMayNotBreak(true); start++; } } }
/** * Defines a range of rows that should not allow a page break (if possible). * * @param start int * @param end int * @throws java.lang.IndexOutOfBoundsException if a row index is passed that * is out of bounds */ public void keepRowsTogether(int start, int end) { if (start < end) { while (start < end) { getRow(start).setMayNotBreak(true); start++; } } }
/** * Defines where the table may be broken (if necessary). * * @param breakPoints int[] * @throws java.lang.IndexOutOfBoundsException if a row index is passed that * is out of bounds */ public void setBreakPoints(int... breakPoints) { keepRowsTogether(0, rows.size()); // sets all rows as unbreakable for (int i = 0; i < breakPoints.length; i++) { getRow(breakPoints[i]).setMayNotBreak(false); } }
/** * Defines where the table may be broken (if necessary). * * @param breakPoints int[] * @throws java.lang.IndexOutOfBoundsException if a row index is passed that * is out of bounds */ public void setBreakPoints(int... breakPoints) { keepRowsTogether(0, rows.size()); // sets all rows as unbreakable for (int i = 0; i < breakPoints.length; i++) { getRow(breakPoints[i]).setMayNotBreak(false); } }
/** * Checks if a cell in a row has a rowspan greater than 1. * * @since 5.1.0 */ public boolean hasRowspan(final int rowIdx) { if (rowIdx < rows.size() && getRow(rowIdx).hasRowspan()) { return true; } PdfPRow previousRow = rowIdx > 0 ? getRow(rowIdx - 1) : null; if (previousRow != null && previousRow.hasRowspan()) { return true; } for (int i = 0; i < getNumberOfColumns(); i++) { if (rowSpanAbove(rowIdx - 1, i)) { return true; } } return false; }
/** * Checks if a cell in a row has a rowspan greater than 1. * * @since 5.1.0 */ public boolean hasRowspan(final int rowIdx) { if (rowIdx < rows.size() && getRow(rowIdx).hasRowspan()) { return true; } PdfPRow previousRow = rowIdx > 0 ? getRow(rowIdx - 1) : null; if (previousRow != null && previousRow.hasRowspan()) { return true; } for (int i = 0; i < getNumberOfColumns(); i++) { if (rowSpanAbove(rowIdx - 1, i)) { return true; } } return false; }
/** * Copies the content of a specific row in a table to this row. Don't do * this if the rows have a different number of cells. * * @param table the table from which you want to copy a row * @param idx the index of the row that needs to be copied * @since 5.1.0 */ public void copyRowContent(PdfPTable table, int idx) { if (table == null) { return; } PdfPCell copy; for (int i = 0; i < cells.length; ++i) { int lastRow = idx; copy = table.getRow(lastRow).getCells()[i]; while (copy == null && lastRow > 0) { copy = table.getRow(--lastRow).getCells()[i]; } if (cells[i] != null && copy != null) { cells[i].setColumn(copy.getColumn()); this.calculated = false; } } }
/** * Copies the content of a specific row in a table to this row. Don't do * this if the rows have a different number of cells. * * @param table the table from which you want to copy a row * @param idx the index of the row that needs to be copied * @since 5.1.0 */ public void copyRowContent(PdfPTable table, int idx) { if (table == null) { return; } PdfPCell copy; for (int i = 0; i < cells.length; ++i) { int lastRow = idx; copy = table.getRow(lastRow).getCells()[i]; while (copy == null && lastRow > 0) { copy = table.getRow(--lastRow).getCells()[i]; } if (cells[i] != null && copy != null) { cells[i].setColumn(copy.getColumn()); this.calculated = false; } } }
/** * Calculates the extra height needed in a row because of rowspans. * * @param start the index of the start row (the one to adjust) * @param end the index of the end row on the page * @since 2.1.6 */ protected PdfPRow adjustCellsInRow(final int start, final int end) { PdfPRow row = getRow(start); if (row.isAdjusted()) { return row; } row = new PdfPRow(row); PdfPCell cell; PdfPCell[] cells = row.getCells(); for (int i = 0; i < cells.length; i++) { cell = cells[i]; if (cell == null || cell.getRowspan() == 1) { continue; } int stop = Math.min(end, start + cell.getRowspan()); float extra = 0; for (int k = start + 1; k < stop; k++) { extra += getRow(k).getMaxHeights(); } row.setExtraHeight(i, extra); } row.setAdjusted(true); return row; }
/** * Calculates the extra height needed in a row because of rowspans. * * @param start the index of the start row (the one to adjust) * @param end the index of the end row on the page * @since 2.1.6 */ protected PdfPRow adjustCellsInRow(final int start, final int end) { PdfPRow row = getRow(start); if (row.isAdjusted()) { return row; } row = new PdfPRow(row); PdfPCell cell; PdfPCell[] cells = row.getCells(); for (int i = 0; i < cells.length; i++) { cell = cells[i]; if (cell == null || cell.getRowspan() == 1) { continue; } int stop = Math.min(end, start + cell.getRowspan()); float extra = 0; for (int k = start + 1; k < stop; k++) { extra += getRow(k).getMaxHeights(); } row.setExtraHeight(i, extra); } row.setAdjusted(true); return row; }
LOGGER.info(String.format("getFittingRows(%s, %s)", availableHeight, startIdx)); if ( startIdx > 0 && startIdx < rows.size() ) { assert (getRow(startIdx).getCells()[0] != null); // top left cell of current page may not be null int k; for (k = startIdx; k < size(); ++k) { PdfPRow row = getRow(k); float rowHeight = row.getMaxRowHeightsWithoutCalculating(); float maxCompletedRowsHeight = 0;