Example usage for com.itextpdf.text.html.simpleparser TableWrapper addRow

List of usage examples for com.itextpdf.text.html.simpleparser TableWrapper addRow

Introduction

In this page you can find the example usage for com.itextpdf.text.html.simpleparser TableWrapper addRow.

Prototype

public void addRow(List<PdfPCell> row) 

Source Link

Document

Adds a new row to the table.

Usage

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

/**
 * Gets the TableWrapper from the Stack and adds a new row.
 * @since 5.0.6/*w  w  w  .j a  v a 2  s.  com*/
 */
public void processRow() {
    ArrayList<PdfPCell> row = new ArrayList<PdfPCell>();
    ArrayList<Float> cellWidths = new ArrayList<Float>();
    boolean percentage = false;
    float width;
    float totalWidth = 0;
    int zeroWidth = 0;
    TableWrapper table = null;
    while (true) {
        Element obj = stack.pop();
        if (obj instanceof CellWrapper) {
            CellWrapper cell = (CellWrapper) obj;
            width = cell.getWidth();
            cellWidths.add(new Float(width));
            percentage |= cell.isPercentage();
            if (width == 0) {
                zeroWidth++;
            } else {
                totalWidth += width;
            }
            row.add(cell.getCell());
        }
        if (obj instanceof TableWrapper) {
            table = (TableWrapper) obj;
            break;
        }
    }
    table.addRow(row);
    if (cellWidths.size() > 0) {
        // cells come off the stack in reverse, naturally
        totalWidth = 100 - totalWidth;
        Collections.reverse(cellWidths);
        float[] widths = new float[cellWidths.size()];
        boolean hasZero = false;
        for (int i = 0; i < widths.length; i++) {
            widths[i] = cellWidths.get(i).floatValue();
            if (widths[i] == 0 && percentage && zeroWidth > 0) {
                widths[i] = totalWidth / zeroWidth;
            }
            if (widths[i] == 0) {
                hasZero = true;
                break;
            }
        }
        if (!hasZero)
            table.setColWidths(widths);
    }
    stack.push(table);
}