Example usage for com.itextpdf.text.pdf ColumnText START_COLUMN

List of usage examples for com.itextpdf.text.pdf ColumnText START_COLUMN

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf ColumnText START_COLUMN.

Prototype

int START_COLUMN

To view the source code for com.itextpdf.text.pdf ColumnText START_COLUMN.

Click Source Link

Document

Initial value of the status.

Usage

From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java

public static void printToPDF(ArrayList<Person> workers, EventGig event) throws IOException, DocumentException {
    String filename = event.getName() + ".pdf";
    String path = event.getData() + " " + event.getName() + "//";

    Document document = new Document();
    // step 2/*from w  w  w . j  a v  a  2  s  . c o  m*/
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + filename));
    // step 3
    document.open();
    // step 4
    ColumnText column = new ColumnText(writer.getDirectContent());

    float[][] x = { { document.left(), document.left() + 230 }, { document.right() - 230, document.right() } };
    for (Person person : workers) {
        column.addElement(MakerPDF.createTable(person, event));
    }
    int count = 0;
    float height = 0;
    int status = ColumnText.START_COLUMN;
    while (ColumnText.hasMoreText(status)) {
        column.setSimpleColumn(x[count][0], document.bottom(), x[count][1], document.top() - height - 10);
        // render as much content as possible
        status = column.go();
        // go to a new page if you've reached the last column
        if (++count > 1) {
            count = 0;
            document.newPage();
        }
    }
    document.newPage();
    document.close();
}

From source file:com.vectorprint.report.itext.style.stylers.SimpleColumns.java

License:Open Source License

/**
 * writes out content taking into account the current vertical position in the document and making sure that the next
 * call to {@link Document#add(com.itextpdf.text.Element)} will start at the correct vertical position.
 *
 * @see #getSpaceBefore()//  w ww .  j a  v a2 s  .  c  o  m
 * @see #getSpaceAfter()
 *
 * @param last when true space will be appended to start adding content at the correct position after the columns
 * @throws DocumentException
 */
public SimpleColumns write(boolean last) throws DocumentException {
    int status = ColumnText.START_COLUMN;
    ct.setSimpleColumn(columns.get(column));
    if (firstWrite) {
        float top = getWriter().getVerticalPosition(false) > getTop() ? getTop()
                : getWriter().getVerticalPosition(false);
        pageTop = minY = top - getValue(Spacing.SPACEBEFOREPARAM, Float.class);
        ct.setYLine(pageTop);
        firstWrite = false;
        if (log.isLoggable(Level.FINE)) {
            log.fine(String.format("first write of columns top for content determined: %s",
                    top - getValue(Spacing.SPACEBEFOREPARAM, Float.class)));
        }
    } else {
        if (log.isLoggable(Level.FINE)) {
            log.fine(String.format("following write of columns, using current top for content: %s", currentY));
        }
        ct.setYLine(currentY);
    }
    while (ColumnText.hasMoreText(status)) {
        if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.DEBUG)) {
            Rectangle rect = new Rectangle(columns.get(column));
            rect.setTop(ct.getYLine());
            DebugHelper.debugRect(ct.getCanvas(), rect, new float[] { 2, 2 }, 0.3f, getSettings(),
                    elementProducer);
        }
        status = ct.go();
        currentY = ct.getYLine();
        if (ct.getYLine() < minY) {
            minY = ct.getYLine();
        }
        if (ColumnText.hasMoreText(status)) {
            if (column == getNumColumns() - 1) {
                column = 0;
                getDocument().newPage();
                minY = pageTop = currentY = getTop();
                if (log.isLoggable(Level.FINE)) {
                    log.fine(String.format("starting next page for columns"));
                }
            } else {
                column++;
                if (log.isLoggable(Level.FINE)) {
                    log.fine(String.format("going to column %s", column));
                }
            }
            ct.setSimpleColumn(columns.get(column));
            ct.setYLine(pageTop);
        } else {
            contentWritten = addedContent;
            if (log.isLoggable(Level.FINE)) {
                log.fine(String.format("column content written %s", addedContent));
            }
        }
    }
    if (last) {
        float space = (pageTop - minY < getBottom())
                ? getBottom() + getValue(Spacing.SPACEAFTERPARAM, Float.class)
                : pageTop - minY + getValue(Spacing.SPACEAFTERPARAM, Float.class);
        // add necessary spacing, space otherwise ignored!
        if (log.isLoggable(Level.FINE)) {
            log.fine(String.format("appending %s mm to start following content at the correct position",
                    ItextHelper.ptsToMm(space)));
        }
        Paragraph p = new Paragraph(" ");
        p.setSpacingAfter(space);
        getDocument().add(p);
    }
    return this;
}