Java Examples for com.itextpdf.text.pdf.PdfPRow
The following java examples will help you to understand the usage of com.itextpdf.text.pdf.PdfPRow. These source code samples are taken from different open source projects.
Example 1
| Project: xdocreport-master File: StylableDocumentSection.java View source code |
private List<ColumnText> fillTable(float height) {
// copy text for simulation
List<ColumnText> tt = null;
if (breakHandlingParent == null && colIdx >= layoutTable.getNumberOfColumns()) {
// more column breaks than available column
// we try not to lose content
// but results may be different than in open office
// anyway it is logical error made by document creator
tt = new ArrayList<ColumnText>();
ColumnText t = createColumnText();
tt.add(t);
for (int i = 0; i < texts.size(); i++) {
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(100.0f);
PdfPCell cell = new PdfPCell();
cell.setBorder(PdfPCell.NO_BORDER);
cell.setPadding(0.0f);
cell.setColumn(ColumnText.duplicate(texts.get(i)));
table.addCell(cell);
t.addElement(table);
}
} else {
tt = new ArrayList<ColumnText>(texts);
for (int i = 0; i < tt.size(); i++) {
tt.set(i, ColumnText.duplicate(tt.get(i)));
}
}
// clear layout table
clearTable(layoutTable, true);
setWidthIfNecessary();
// try to fill cells with text
ColumnText t = tt.get(0);
for (PdfPCell cell : layoutTable.getRow(0).getCells()) {
cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
cell.setColumn(ColumnText.duplicate(t));
//
t.setSimpleColumn(cell.getLeft() + cell.getPaddingLeft(), height >= 0.0f ? -height : PdfPRow.BOTTOM_LIMIT, cell.getRight() - cell.getPaddingRight(), 0);
int res = 0;
try {
res = t.go(true);
} catch (DocumentException e) {
throw new ODFConverterException(e);
}
if (!ColumnText.hasMoreText(res)) {
// no overflow in current column
if (tt.size() == 1) {
// no more text
return null;
} else {
// some text waiting for new column
tt.remove(0);
t = tt.get(0);
}
}
}
return tt;
}Example 2
| Project: micmiu-xmlworker-master File: Table.java View source code |
/**
* Sets the default cell width and widest word of a cell.
* <ul>
* <li>cell width = {@link Table#getCellStartWidth(HtmlCell)} + the width of
* the widest line of text.</li>
* <li>widest word = {@link Table#getCellStartWidth(HtmlCell)} + the widest
* word of the cell.</li>
* </ul>
* These 2 widths are used as the starting point when determining the width
* of the table in
*
* @param cell HtmlCell of which the widths are needed.
* @return float array containing the default cell width and the widest
* word.
* <ul>
* <li>float[0] = cell width.</li>
* <li>float[1] = widest word.</li>
* </ul>
*/
private float[] setCellWidthAndWidestWord(final HtmlCell cell) {
List<Float> rulesWidth = new ArrayList<Float>();
float widestWordOfCell = 0f;
float startWidth = getCellStartWidth(cell);
float cellWidth = startWidth;
List<Element> compositeElements = cell.getCompositeElements();
if (compositeElements != null) {
for (Element baseLevel : compositeElements) {
if (baseLevel instanceof Phrase) {
for (int i = 0; i < ((Phrase) baseLevel).size(); i++) {
Element inner = ((Phrase) baseLevel).get(i);
if (inner instanceof Chunk) {
cellWidth += ((Chunk) inner).getWidthPoint();
float widestWord = startWidth + getCssAppliers().getChunkCssAplier().getWidestWord((Chunk) inner);
if (widestWord > widestWordOfCell) {
widestWordOfCell = widestWord;
}
}
}
rulesWidth.add(cellWidth);
cellWidth = startWidth;
} else if (baseLevel instanceof com.itextpdf.text.List) {
for (Element li : ((com.itextpdf.text.List) baseLevel).getItems()) {
rulesWidth.add(cellWidth);
cellWidth = startWidth + ((ListItem) li).getIndentationLeft();
for (Chunk c : ((ListItem) li).getChunks()) {
cellWidth += c.getWidthPoint();
float widestWord = getCssAppliers().getChunkCssAplier().getWidestWord(c);
if (startWidth + widestWord > widestWordOfCell) {
widestWordOfCell = startWidth + widestWord;
}
}
}
rulesWidth.add(cellWidth);
cellWidth = startWidth;
} else if (baseLevel instanceof PdfPTable) {
rulesWidth.add(cellWidth);
cellWidth = startWidth + ((PdfPTable) baseLevel).getTotalWidth();
for (PdfPRow innerRow : ((PdfPTable) baseLevel).getRows()) {
int size = innerRow.getCells().length;
TableBorderEvent event = (TableBorderEvent) ((PdfPTable) baseLevel).getTableEvent();
TableStyleValues values = event.getTableStyleValues();
float minRowWidth = values.getBorderWidthLeft() + (size + 1) * values.getHorBorderSpacing() + values.getBorderWidthRight();
int celnr = 0;
for (PdfPCell innerCell : innerRow.getCells()) {
celnr++;
if (innerCell != null) {
float innerWidestWordOfCell = setCellWidthAndWidestWord(new HtmlCell(innerCell, celnr == size))[1];
minRowWidth += innerWidestWordOfCell;
}
}
if (minRowWidth > widestWordOfCell) {
widestWordOfCell = minRowWidth;
}
}
rulesWidth.add(cellWidth);
cellWidth = startWidth;
}
}
}
for (Float width : rulesWidth) {
if (width > cellWidth) {
cellWidth = width;
}
}
return new float[] { cellWidth, widestWordOfCell };
}Example 3
| Project: nextreports-engine-master File: PdfExporter.java View source code |
private float computeFooterHeight() throws QueryException {
footer = buildPdfTable(PRINT_PAGE_FOOTER);
if (footer == null) {
return 0;
}
printPageFooterBand();
float height = 0;
ArrayList<PdfPRow> rows = footer.getRows();
for (int k = 0; k < rows.size(); k++) {
PdfPRow row = rows.get(k);
PdfPCell[] cells = row.getCells();
float rowHeight = 0;
for (PdfPCell cell : cells) {
if (cell == null) {
rowHeight = Math.max(rowHeight, MINIMUM_HEIGHT);
} else {
rowHeight = Math.max(rowHeight, cell.getMaxHeight());
}
}
height += rowHeight;
}
return height;
}Example 4
| Project: itextpdf-master File: PdfPTableEventForwarder.java View source code |
/**
* @see com.itextpdf.text.pdf.PdfPTableEventAfterSplit#afterSplitTable(com.itextpdf.text.pdf.PdfPTable, com.itextpdf.text.pdf.PdfPRow, int)
* @since iText 5.4.3
*/
public void afterSplitTable(PdfPTable table, PdfPRow startRow, int startIdx) {
for (PdfPTableEvent event : events) {
if (event instanceof PdfPTableEventAfterSplit)
((PdfPTableEventAfterSplit) event).afterSplitTable(table, startRow, startIdx);
}
}Example 5
| Project: elmis-master File: RequisitionPdfModelTest.java View source code |
private void assertRowValues(PdfPRow row, String... cellTexts) {
PdfPCell[] rowCells = row.getCells();
int index = 0;
for (String text : cellTexts) {
assertThat(rowCells[index++].getPhrase().getContent(), is(text));
}
}Example 6
| Project: Assignments-master File: PdfPTableEventForwarder.java View source code |
/**
* @see com.itextpdf.text.pdf.PdfPTableEventAfterSplit#afterSplitTable(com.itextpdf.text.pdf.PdfPTable, com.itextpdf.text.pdf.PdfPRow, int)
* @since iText 5.4.3
*/
public void afterSplitTable(PdfPTable table, PdfPRow startRow, int startIdx) {
for (PdfPTableEvent event : events) {
if (event instanceof PdfPTableEventAfterSplit)
((PdfPTableEventAfterSplit) event).afterSplitTable(table, startRow, startIdx);
}
}