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

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

Introduction

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

Prototype

public float getTotalHeight() 

Source Link

Document

Gets the total height of the table.

Usage

From source file:questions.tables.TablesWriteSelected.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate());
    try {//w w w  .j a  v  a  2  s.c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));

        document.open();

        // the content of the columns
        PdfPTable items = new PdfPTable(2);
        items.setTotalWidth(TOTAL_WIDTH);
        for (int i = 0; i < 100; ++i) {
            items.addCell("item " + i);
            items.addCell("some item");
        }
        int rows = items.size();

        // adding the stuff to the document
        int column = 0;
        int start;
        int end = 0;
        int row = 0;
        float available = 0;
        float[][] x = { { document.left(), document.left() + TOTAL_WIDTH },
                { document.right() - TOTAL_WIDTH, document.right() } };
        while (row < rows) {
            start = row;
            if (column == 0) {
                PdfPTable table = new PdfPTable(1);
                table.setWidthPercentage(100);
                table.addCell("EmployeeSheets");
                table.addCell("Page " + writer.getPageNumber());
                document.add(table);
                available = document.top() - table.getTotalHeight() - 10 - document.bottom();
            }
            float needed = items.getRowHeight(start);
            while (needed < available && row < rows) {
                needed += items.getRowHeight(++row);
                end = row;
            }
            items.writeSelectedRows(start, end, x[column][0], document.bottom() + available,
                    writer.getDirectContent());
            if (++column >= x.length) {
                column = 0;
                document.newPage();
            }
        }
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}