Example usage for com.lowagie.text.pdf PdfPTable getRow

List of usage examples for com.lowagie.text.pdf PdfPTable getRow

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable getRow.

Prototype

public PdfPRow getRow(int idx) 

Source Link

Document

Gets a row with a given index (added by Jin-Hsia Yang).

Usage

From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java

License:Open Source License

private static void addTable(Document pdfDocument, Chapter pdfSheet, int totalWidth, float[] widths,
        PdfPTable pdfTable) throws Exception {
    final int MAX_WIDTH = (int) (pdfDocument.getPageSize().getWidth() / 842 * 65000);
    //      if(totalWidth>MAX_WIDTH) {
    //Split the tables in subcolumns
    for (int offset = 0; offset < pdfTable.getNumberOfColumns();) {
        if (offset > 0)
            pdfSheet.add(new Chunk(" "));

        //Calculates the indexes that fit the page: [offset; index2]
        int subTotalWidth = 0;
        int index2;
        for (index2 = offset; index2 < pdfTable.getNumberOfColumns() && subTotalWidth < MAX_WIDTH; index2++) {
            subTotalWidth += widths[index2] * totalWidth;
        }/*from   ww w.j  a  v a  2 s .c  o  m*/
        index2 = Math.min(index2, pdfTable.getNumberOfColumns() - 1);

        //Calculates the new sub widths
        float[] subWidths = new float[index2 - offset + 2];
        for (int i = 0; i < subWidths.length - 1; i++) {
            subWidths[i] = widths[offset + i] * totalWidth / MAX_WIDTH;
        }
        subWidths[subWidths.length - 1] = Math.max(0, (float) (MAX_WIDTH - subTotalWidth) / MAX_WIDTH);
        System.out.println("PDFUtils.addTable() " + Arrays.toString(subWidths));

        //Creates the new sub widths
        PdfPTable subtable = new PdfPTable(subWidths.length);
        subtable.setWidths(subWidths);
        for (int r = 0; r < pdfTable.getRows().size(); r++) {
            for (int c = 0; c < index2 - offset + 1; c++) {
                PdfPCell cell = pdfTable.getRow(r).getCells()[c + offset];
                subtable.addCell(cell);
            }
            PdfPCell pdfCell = new PdfPCell();
            pdfCell.setBorder(0);
            subtable.addCell(pdfCell);
        }

        subtable.setWidthPercentage(100);
        collapseBorder(subtable);
        pdfSheet.add(subtable);

        //Go to the next index offset
        offset = index2 + 1;
    }
    //      } else {
    //         //Calculates the new sub widths
    //         float[] subWidths = new float[widths.length+1];
    //         for (int i = 0; i < subWidths.length-1; i++) {
    //            subWidths[i] = widths[0]*totalWidth/MAX_WIDTH;
    //         }
    //         subWidths[subWidths.length-1] = Math.max(0, (float)(MAX_WIDTH-totalWidth)/MAX_WIDTH);
    //         pdfTable.setWidths(subWidths);
    //         pdfTable.setWidthPercentage(100);
    //         collapseBorder(pdfTable);
    //         pdfSheet.add(pdfTable);
    //      }
}

From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java

License:Open Source License

private static void collapseBorder(PdfPTable pdfTable) {
    for (int r = 0; r < pdfTable.getRows().size(); r++) {
        for (int c = 0; c < pdfTable.getNumberOfColumns(); c++) {
            PdfPCell cell = pdfTable.getRow(r).getCells()[c];
            if (cell.getBorderWidthTop() > 0 && r > 0) {
                PdfPCell cell2 = pdfTable.getRow(r - 1).getCells()[c];
                if (cell2.getBorderWidthBottom() > 0)
                    cell.setBorderWidthTop(0);
            }//  w w  w.  java 2s.  co m
            if (cell.getBorderWidthLeft() > 0 && c > 0) {
                PdfPCell cell2 = pdfTable.getRow(r).getCells()[c - 1];
                if (cell2.getBorderWidthRight() > 0)
                    cell.setBorderWidthLeft(0);
            }
        }
    }
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

public static void replaceTableCells(PdfPTable table) {
    // replace default table cells
    // by fixed height cells
    PdfPCell[] cells = table.getRow(0).getCells();
    for (int i = 0; i < cells.length; i++) {
        cells[i] = new FixedHeightPdfPCell(cells[i]);
    }/*from ww w  . j  a  va 2 s. c  o  m*/
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

public static PdfPCell getCell(PdfPTable table, int idx) {
    return table.getRow(0).getCells()[idx];
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

public static void clearTable(PdfPTable table, boolean resetFixedHeight) {
    for (PdfPCell cell : table.getRow(0).getCells()) {
        cell.setColumn(createColumnText());
        if (resetFixedHeight) {
            cell.setFixedHeight(-1.0f);//from  w ww  . ja v  a 2  s  .c  o m
        }
    }
}