|
|
@ -65,13 +65,14 @@ import com.fr.third.v2.lowagie.text.pdf.events.PdfPTableEventForwarder; |
|
|
|
* be added to the document as the class <CODE>Table</CODE>. |
|
|
|
* be added to the document as the class <CODE>Table</CODE>. |
|
|
|
* In the last case when crossing pages the table always break at full rows; if a |
|
|
|
* In the last case when crossing pages the table always break at full rows; if a |
|
|
|
* row is bigger than the page it is dropped silently to avoid infinite loops. |
|
|
|
* row is bigger than the page it is dropped silently to avoid infinite loops. |
|
|
|
* <P> |
|
|
|
* <p> |
|
|
|
* A PdfPTableEvent can be associated to the table to do custom drawing |
|
|
|
* A PdfPTableEvent can be associated to the table to do custom drawing |
|
|
|
* when the table is rendered. |
|
|
|
* when the table is rendered. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Paulo Soares (psoares@consiste.pt) |
|
|
|
* @author Paulo Soares (psoares@consiste.pt) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
public class PdfPTable implements LargeElement { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The index of the original <CODE>PdfcontentByte</CODE>. |
|
|
|
* The index of the original <CODE>PdfcontentByte</CODE>. |
|
|
@ -97,11 +98,20 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
protected float totalHeight = 0; |
|
|
|
protected float totalHeight = 0; |
|
|
|
protected PdfPCell currentRow[]; |
|
|
|
protected PdfPCell currentRow[]; |
|
|
|
protected int currentRowIdx = 0; |
|
|
|
protected int currentRowIdx = 0; |
|
|
|
protected PdfPCell defaultCell = new PdfPCell((Phrase)null); |
|
|
|
protected PdfPCell defaultCell = new PdfPCell((Phrase) null); |
|
|
|
protected float totalWidth = 0; |
|
|
|
protected float totalWidth = 0; |
|
|
|
protected float relativeWidths[]; |
|
|
|
protected float relativeWidths[]; |
|
|
|
protected float absoluteWidths[]; |
|
|
|
protected float absoluteWidths[]; |
|
|
|
protected PdfPTableEvent tableEvent; |
|
|
|
protected PdfPTableEvent tableEvent; |
|
|
|
|
|
|
|
private TableProperties tableProperties; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TableProperties getTableProperties() { |
|
|
|
|
|
|
|
return tableProperties; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setTableProperties(TableProperties tableProperties) { |
|
|
|
|
|
|
|
this.tableProperties = tableProperties; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Holds value of property headerRows. |
|
|
|
* Holds value of property headerRows. |
|
|
@ -124,6 +134,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
private boolean skipFirstHeader = false; |
|
|
|
private boolean skipFirstHeader = false; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Holds value of property skipLastFooter. |
|
|
|
* Holds value of property skipLastFooter. |
|
|
|
|
|
|
|
* |
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private boolean skipLastFooter = false; |
|
|
|
private boolean skipLastFooter = false; |
|
|
@ -187,6 +198,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Keeps track of the completeness of the current row. |
|
|
|
* Keeps track of the completeness of the current row. |
|
|
|
|
|
|
|
* |
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected boolean rowCompleted = true; |
|
|
|
protected boolean rowCompleted = true; |
|
|
@ -242,7 +254,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
currentRow[k] = new PdfPCell(table.currentRow[k]); |
|
|
|
currentRow[k] = new PdfPCell(table.currentRow[k]); |
|
|
|
} |
|
|
|
} |
|
|
|
for (int k = 0; k < table.rows.size(); ++k) { |
|
|
|
for (int k = 0; k < table.rows.size(); ++k) { |
|
|
|
PdfPRow row = (PdfPRow)(table.rows.get(k)); |
|
|
|
PdfPRow row = (PdfPRow) (table.rows.get(k)); |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
row = new PdfPRow(row); |
|
|
|
row = new PdfPRow(row); |
|
|
|
rows.add(row); |
|
|
|
rows.add(row); |
|
|
@ -295,6 +307,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
horizontalAlignment = sourceTable.horizontalAlignment; |
|
|
|
horizontalAlignment = sourceTable.horizontalAlignment; |
|
|
|
keepTogether = sourceTable.keepTogether; |
|
|
|
keepTogether = sourceTable.keepTogether; |
|
|
|
complete = sourceTable.complete; |
|
|
|
complete = sourceTable.complete; |
|
|
|
|
|
|
|
tableProperties = sourceTable.tableProperties; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -312,7 +325,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
absoluteWidths = new float[relativeWidths.length]; |
|
|
|
absoluteWidths = new float[relativeWidths.length]; |
|
|
|
totalHeight = 0; |
|
|
|
totalHeight = 0; |
|
|
|
calculateWidths(); |
|
|
|
calculateWidths(); |
|
|
|
calculateHeights(true); |
|
|
|
// calculateHeights(true);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -337,10 +350,12 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
return; |
|
|
|
return; |
|
|
|
float total = 0; |
|
|
|
float total = 0; |
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
|
|
|
|
float cellSpacings = tableProperties.isCollapse() ? 0 : tableProperties.getCellspacing(); |
|
|
|
|
|
|
|
float borderWidth = tableProperties.getBorderStyle().getBorderWidth(); |
|
|
|
for (int k = 0; k < numCols; ++k) |
|
|
|
for (int k = 0; k < numCols; ++k) |
|
|
|
total += relativeWidths[k]; |
|
|
|
total += relativeWidths[k]; |
|
|
|
for (int k = 0; k < numCols; ++k) |
|
|
|
for (int k = 0; k < numCols; ++k) |
|
|
|
absoluteWidths[k] = totalWidth * relativeWidths[k] / total; |
|
|
|
absoluteWidths[k] = (totalWidth-(cellSpacings+ borderWidth)*(numCols+1)) * relativeWidths[k] / total; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -354,7 +369,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
this.totalWidth = totalWidth; |
|
|
|
this.totalWidth = totalWidth; |
|
|
|
totalHeight = 0; |
|
|
|
totalHeight = 0; |
|
|
|
calculateWidths(); |
|
|
|
calculateWidths(); |
|
|
|
calculateHeights(true); |
|
|
|
// calculateHeights(true);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -414,9 +429,13 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
if (totalWidth <= 0) |
|
|
|
if (totalWidth <= 0) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
totalHeight = 0; |
|
|
|
totalHeight = 0; |
|
|
|
|
|
|
|
BorderStyle borderStyle = tableProperties.getBorderStyle(); |
|
|
|
|
|
|
|
float borderWidth = borderStyle.getBorderWidth(); |
|
|
|
|
|
|
|
float cellspacing = tableProperties.getCellspacing(); |
|
|
|
for (int k = 0; k < rows.size(); ++k) { |
|
|
|
for (int k = 0; k < rows.size(); ++k) { |
|
|
|
totalHeight += getRowHeight(k, firsttime); |
|
|
|
totalHeight += getRowHeight(k, firsttime); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
totalHeight += (borderWidth + cellspacing) * (rows.size() + 1); |
|
|
|
return totalHeight; |
|
|
|
return totalHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -486,7 +505,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
PdfPRow row = new PdfPRow(currentRow); |
|
|
|
PdfPRow row = new PdfPRow(currentRow); |
|
|
|
if (totalWidth > 0) { |
|
|
|
if (totalWidth > 0) { |
|
|
|
row.setWidths(absoluteWidths); |
|
|
|
row.setWidths(absoluteWidths); |
|
|
|
totalHeight += row.getMaxHeights(); |
|
|
|
// totalHeight += row.getMaxHeights();
|
|
|
|
} |
|
|
|
} |
|
|
|
rows.add(row); |
|
|
|
rows.add(row); |
|
|
|
currentRow = new PdfPCell[numCols]; |
|
|
|
currentRow = new PdfPCell[numCols]; |
|
|
@ -503,6 +522,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* When updating the row index, cells with rowspan should be taken into account. |
|
|
|
* When updating the row index, cells with rowspan should be taken into account. |
|
|
|
* This is what happens in this method. |
|
|
|
* This is what happens in this method. |
|
|
|
|
|
|
|
* |
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void skipColsWithRowspanAbove() { |
|
|
|
private void skipColsWithRowspanAbove() { |
|
|
@ -515,6 +535,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Checks if there are rows above belonging to a rowspan. |
|
|
|
* Checks if there are rows above belonging to a rowspan. |
|
|
|
|
|
|
|
* |
|
|
|
* @param currRow the current row to check |
|
|
|
* @param currRow the current row to check |
|
|
|
* @param currCol the current column to check |
|
|
|
* @param currCol the current column to check |
|
|
|
* @return true if there's a cell above that belongs to a rowspan |
|
|
|
* @return true if there's a cell above that belongs to a rowspan |
|
|
@ -528,34 +549,34 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
int row = currRow - 1; |
|
|
|
int row = currRow - 1; |
|
|
|
PdfPRow aboveRow = (PdfPRow)rows.get(row); |
|
|
|
PdfPRow aboveRow = (PdfPRow) rows.get(row); |
|
|
|
if (aboveRow == null) |
|
|
|
if (aboveRow == null) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
PdfPCell aboveCell = (PdfPCell)aboveRow.getCells()[currCol]; |
|
|
|
PdfPCell aboveCell = (PdfPCell) aboveRow.getCells()[currCol]; |
|
|
|
while ((aboveCell == null) && (row > 0)) { |
|
|
|
while ((aboveCell == null) && (row > 0)) { |
|
|
|
aboveRow = (PdfPRow)rows.get(--row); |
|
|
|
aboveRow = (PdfPRow) rows.get(--row); |
|
|
|
if (aboveRow == null) |
|
|
|
if (aboveRow == null) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[currCol]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[currCol]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int distance = currRow - row; |
|
|
|
int distance = currRow - row; |
|
|
|
|
|
|
|
|
|
|
|
if (aboveCell == null) { |
|
|
|
if (aboveCell == null) { |
|
|
|
int col = currCol - 1; |
|
|
|
int col = currCol - 1; |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[col]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[col]; |
|
|
|
while ((aboveCell == null) && (row > 0)) |
|
|
|
while ((aboveCell == null) && (row > 0)) |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[--col]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[--col]; |
|
|
|
return aboveCell != null && aboveCell.getRowspan() > distance; |
|
|
|
return aboveCell != null && aboveCell.getRowspan() > distance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ((aboveCell.getRowspan() == 1) && (distance > 1)) { |
|
|
|
if ((aboveCell.getRowspan() == 1) && (distance > 1)) { |
|
|
|
int col = currCol - 1; |
|
|
|
int col = currCol - 1; |
|
|
|
aboveRow = (PdfPRow)rows.get(row + 1); |
|
|
|
aboveRow = (PdfPRow) rows.get(row + 1); |
|
|
|
distance--; |
|
|
|
distance--; |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[col]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[col]; |
|
|
|
while ((aboveCell == null) && (col > 0)) |
|
|
|
while ((aboveCell == null) && (col > 0)) |
|
|
|
aboveCell = (PdfPCell)aboveRow.getCells()[--col]; |
|
|
|
aboveCell = (PdfPCell) aboveRow.getCells()[--col]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return aboveCell != null && aboveCell.getRowspan() > distance; |
|
|
|
return aboveCell != null && aboveCell.getRowspan() > distance; |
|
|
@ -669,7 +690,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
|
|
|
|
|
|
|
|
float yPosStart = yPos; |
|
|
|
float yPosStart = yPos; |
|
|
|
for (int k = rowStart; k < rowEnd; ++k) { |
|
|
|
for (int k = rowStart; k < rowEnd; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
if (row != null) { |
|
|
|
if (row != null) { |
|
|
|
row.writeCells(colStart, colEnd, xPos, yPos, canvases); |
|
|
|
row.writeCells(colStart, colEnd, xPos, yPos, canvases); |
|
|
|
yPos -= row.getMaxHeights(); |
|
|
|
yPos -= row.getMaxHeights(); |
|
|
@ -680,7 +701,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
float heights[] = new float[rowEnd - rowStart + 1]; |
|
|
|
float heights[] = new float[rowEnd - rowStart + 1]; |
|
|
|
heights[0] = yPosStart; |
|
|
|
heights[0] = yPosStart; |
|
|
|
for (int k = rowStart; k < rowEnd; ++k) { |
|
|
|
for (int k = rowStart; k < rowEnd; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
float hr = 0; |
|
|
|
float hr = 0; |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
hr = row.getMaxHeights(); |
|
|
|
hr = row.getMaxHeights(); |
|
|
@ -834,6 +855,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
public float getRowHeight(int idx) { |
|
|
|
public float getRowHeight(int idx) { |
|
|
|
return getRowHeight(idx, false); |
|
|
|
return getRowHeight(idx, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Gets the height of a particular row. |
|
|
|
* Gets the height of a particular row. |
|
|
|
* |
|
|
|
* |
|
|
@ -845,7 +867,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
public float getRowHeight(int idx, boolean firsttime) { |
|
|
|
public float getRowHeight(int idx, boolean firsttime) { |
|
|
|
if (totalWidth <= 0 || idx < 0 || idx >= rows.size()) |
|
|
|
if (totalWidth <= 0 || idx < 0 || idx >= rows.size()) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
PdfPRow row = (PdfPRow)rows.get(idx); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(idx); |
|
|
|
if (row == null) |
|
|
|
if (row == null) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
if (firsttime) |
|
|
|
if (firsttime) |
|
|
@ -854,13 +876,13 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
PdfPCell cell; |
|
|
|
PdfPCell cell; |
|
|
|
PdfPRow tmprow; |
|
|
|
PdfPRow tmprow; |
|
|
|
for (int i = 0; i < relativeWidths.length; i++) { |
|
|
|
for (int i = 0; i < relativeWidths.length; i++) { |
|
|
|
if(!rowSpanAbove(idx, i)) |
|
|
|
if (!rowSpanAbove(idx, i)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
int rs = 1; |
|
|
|
int rs = 1; |
|
|
|
while (rowSpanAbove(idx - rs, i)) { |
|
|
|
while (rowSpanAbove(idx - rs, i)) { |
|
|
|
rs++; |
|
|
|
rs++; |
|
|
|
} |
|
|
|
} |
|
|
|
tmprow = (PdfPRow)rows.get(idx - rs); |
|
|
|
tmprow = (PdfPRow) rows.get(idx - rs); |
|
|
|
cell = tmprow.getCells()[i]; |
|
|
|
cell = tmprow.getCells()[i]; |
|
|
|
float tmp = 0; |
|
|
|
float tmp = 0; |
|
|
|
if (cell.getRowspan() == rs + 1) { |
|
|
|
if (cell.getRowspan() == rs + 1) { |
|
|
@ -881,15 +903,15 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
* Gets the maximum height of a cell in a particular row (will only be different |
|
|
|
* Gets the maximum height of a cell in a particular row (will only be different |
|
|
|
* from getRowHeight is one of the cells in the row has a rowspan > 1). |
|
|
|
* from getRowHeight is one of the cells in the row has a rowspan > 1). |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @return the height of a particular row including rowspan |
|
|
|
* @param rowIndex the row index |
|
|
|
* @param rowIndex the row index |
|
|
|
* @param cellIndex the cell index |
|
|
|
* @param cellIndex the cell index |
|
|
|
* @return the height of a particular row including rowspan |
|
|
|
|
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public float getRowspanHeight(int rowIndex, int cellIndex) { |
|
|
|
public float getRowspanHeight(int rowIndex, int cellIndex) { |
|
|
|
if (totalWidth <= 0 || rowIndex < 0 || rowIndex >= rows.size()) |
|
|
|
if (totalWidth <= 0 || rowIndex < 0 || rowIndex >= rows.size()) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
PdfPRow row = (PdfPRow)rows.get(rowIndex); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(rowIndex); |
|
|
|
if (row == null || cellIndex >= row.getCells().length) |
|
|
|
if (row == null || cellIndex >= row.getCells().length) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
PdfPCell cell = row.getCells()[cellIndex]; |
|
|
|
PdfPCell cell = row.getCells()[cellIndex]; |
|
|
@ -912,7 +934,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
float total = 0; |
|
|
|
float total = 0; |
|
|
|
int size = Math.min(rows.size(), headerRows); |
|
|
|
int size = Math.min(rows.size(), headerRows); |
|
|
|
for (int k = 0; k < size; ++k) { |
|
|
|
for (int k = 0; k < size; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
total += row.getMaxHeights(); |
|
|
|
total += row.getMaxHeights(); |
|
|
|
} |
|
|
|
} |
|
|
@ -931,7 +953,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
int start = Math.max(0, headerRows - footerRows); |
|
|
|
int start = Math.max(0, headerRows - footerRows); |
|
|
|
int size = Math.min(rows.size(), headerRows); |
|
|
|
int size = Math.min(rows.size(), headerRows); |
|
|
|
for (int k = start; k < size; ++k) { |
|
|
|
for (int k = start; k < size; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
total += row.getMaxHeights(); |
|
|
|
total += row.getMaxHeights(); |
|
|
|
} |
|
|
|
} |
|
|
@ -948,7 +970,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
if (rowNumber < 0 || rowNumber >= rows.size()) |
|
|
|
if (rowNumber < 0 || rowNumber >= rows.size()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (totalWidth > 0) { |
|
|
|
if (totalWidth > 0) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(rowNumber); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(rowNumber); |
|
|
|
if (row != null) |
|
|
|
if (row != null) |
|
|
|
totalHeight -= row.getMaxHeights(); |
|
|
|
totalHeight -= row.getMaxHeights(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1034,16 +1056,16 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @see Element#isContent() |
|
|
|
|
|
|
|
* @since iText 2.0.8 |
|
|
|
* @since iText 2.0.8 |
|
|
|
|
|
|
|
* @see Element#isContent() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isContent() { |
|
|
|
public boolean isContent() { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @see Element#isNestable() |
|
|
|
|
|
|
|
* @since iText 2.0.8 |
|
|
|
* @since iText 2.0.8 |
|
|
|
|
|
|
|
* @see Element#isNestable() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isNestable() { |
|
|
|
public boolean isNestable() { |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -1059,8 +1081,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
public boolean process(ElementListener listener) { |
|
|
|
public boolean process(ElementListener listener) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return listener.add(this); |
|
|
|
return listener.add(this); |
|
|
|
} |
|
|
|
} catch (DocumentException de) { |
|
|
|
catch(DocumentException de) { |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1111,7 +1132,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
* @return the row at position idx |
|
|
|
* @return the row at position idx |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public PdfPRow getRow(int idx) { |
|
|
|
public PdfPRow getRow(int idx) { |
|
|
|
return (PdfPRow)rows.get(idx); |
|
|
|
return (PdfPRow) rows.get(idx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -1125,6 +1146,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Gets an arraylist with a selection of rows. |
|
|
|
* Gets an arraylist with a selection of rows. |
|
|
|
|
|
|
|
* |
|
|
|
* @param start the first row in the selection |
|
|
|
* @param start the first row in the selection |
|
|
|
* @param end the first row that isn't part of the selection |
|
|
|
* @param end the first row that isn't part of the selection |
|
|
|
* @return a selection of rows |
|
|
|
* @return a selection of rows |
|
|
@ -1173,6 +1195,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Calculates the extra height needed in a row because of rowspans. |
|
|
|
* Calculates the extra height needed in a row because of rowspans. |
|
|
|
|
|
|
|
* |
|
|
|
* @param start the index of the start row (the one to adjust) |
|
|
|
* @param start the index of the start row (the one to adjust) |
|
|
|
* @param end the index of the end row on the page |
|
|
|
* @param end the index of the end row on the page |
|
|
|
* @since 2.1.6 |
|
|
|
* @since 2.1.6 |
|
|
@ -1196,7 +1219,9 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
return row; |
|
|
|
return row; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Sets the table event for this table. |
|
|
|
/** |
|
|
|
|
|
|
|
* Sets the table event for this table. |
|
|
|
|
|
|
|
* |
|
|
|
* @param event the table event for this table |
|
|
|
* @param event the table event for this table |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setTableEvent(PdfPTableEvent event) { |
|
|
|
public void setTableEvent(PdfPTableEvent event) { |
|
|
@ -1205,7 +1230,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
else if (this.tableEvent == null) |
|
|
|
else if (this.tableEvent == null) |
|
|
|
this.tableEvent = event; |
|
|
|
this.tableEvent = event; |
|
|
|
else if (this.tableEvent instanceof PdfPTableEventForwarder) |
|
|
|
else if (this.tableEvent instanceof PdfPTableEventForwarder) |
|
|
|
((PdfPTableEventForwarder)this.tableEvent).addTableEvent(event); |
|
|
|
((PdfPTableEventForwarder) this.tableEvent).addTableEvent(event); |
|
|
|
else { |
|
|
|
else { |
|
|
|
PdfPTableEventForwarder forward = new PdfPTableEventForwarder(); |
|
|
|
PdfPTableEventForwarder forward = new PdfPTableEventForwarder(); |
|
|
|
forward.addTableEvent(this.tableEvent); |
|
|
|
forward.addTableEvent(this.tableEvent); |
|
|
@ -1232,7 +1257,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
return absoluteWidths; |
|
|
|
return absoluteWidths; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float [][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders) { |
|
|
|
float[][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders) { |
|
|
|
if (includeHeaders) { |
|
|
|
if (includeHeaders) { |
|
|
|
firstRow = Math.max(firstRow, headerRows); |
|
|
|
firstRow = Math.max(firstRow, headerRows); |
|
|
|
lastRow = Math.max(lastRow, headerRows); |
|
|
|
lastRow = Math.max(lastRow, headerRows); |
|
|
@ -1242,7 +1267,7 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
int n = 0; |
|
|
|
int n = 0; |
|
|
|
if (includeHeaders) { |
|
|
|
if (includeHeaders) { |
|
|
|
for (int k = 0; k < headerRows; ++k) { |
|
|
|
for (int k = 0; k < headerRows; ++k) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(k); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(k); |
|
|
|
if (row == null) |
|
|
|
if (row == null) |
|
|
|
++n; |
|
|
|
++n; |
|
|
|
else |
|
|
|
else |
|
|
@ -1250,14 +1275,13 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (; firstRow < lastRow; ++firstRow) { |
|
|
|
for (; firstRow < lastRow; ++firstRow) { |
|
|
|
PdfPRow row = (PdfPRow)rows.get(firstRow); |
|
|
|
PdfPRow row = (PdfPRow) rows.get(firstRow); |
|
|
|
if (row == null) |
|
|
|
if (row == null) |
|
|
|
++n; |
|
|
|
++n; |
|
|
|
else |
|
|
|
else |
|
|
|
widths[n++] = row.getEventWidth(xPos); |
|
|
|
widths[n++] = row.getEventWidth(xPos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
else { |
|
|
|
|
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
int numCols = getNumberOfColumns(); |
|
|
|
float width[] = new float[numCols + 1]; |
|
|
|
float width[] = new float[numCols + 1]; |
|
|
|
width[0] = xPos; |
|
|
|
width[0] = xPos; |
|
|
@ -1560,41 +1584,5 @@ public class PdfPTable implements LargeElement, PdfBlock { |
|
|
|
this.complete = complete; |
|
|
|
this.complete = complete; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public float getHeight() { |
|
|
|
|
|
|
|
return getTotalHeight(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void calculateHeight() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String toHtmlString(double startY, double endY) { |
|
|
|
|
|
|
|
StringBuffer a = new StringBuffer(); |
|
|
|
|
|
|
|
float currentHeight = 0.0f; |
|
|
|
|
|
|
|
a.append("<table>"); |
|
|
|
|
|
|
|
for(Object r : rows){ |
|
|
|
|
|
|
|
PdfPRow row = (PdfPRow) r; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(currentHeight>=startY && currentHeight+ row.getMaxHeights() <= endY){ |
|
|
|
|
|
|
|
a.append("<tr>"); |
|
|
|
|
|
|
|
for(PdfPCell cell : row.getCells()){ |
|
|
|
|
|
|
|
a.append(cell.getContainer().getHtmlContent(0, cell.getHeight())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
a.append("</tr>"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
currentHeight+=row.getMaxHeights(); |
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if(currentHeight <= y && currentHeight + row.getMaxHeights() >x){
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }else{
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
a.append("</table>"); |
|
|
|
|
|
|
|
return a.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |