Example usage for com.lowagie.text.pdf ColumnText NO_MORE_COLUMN

List of usage examples for com.lowagie.text.pdf ColumnText NO_MORE_COLUMN

Introduction

In this page you can find the example usage for com.lowagie.text.pdf ColumnText NO_MORE_COLUMN.

Prototype

int NO_MORE_COLUMN

To view the source code for com.lowagie.text.pdf ColumnText NO_MORE_COLUMN.

Click Source Link

Document

Signals that there is no more column.

Usage

From source file:corner.orm.tapestry.jasper.exporter.CornerPdfExporter.java

License:Apache License

/**
 * ?.????.//from   ww w  .j  a va 2 s.c  o  m
 * <p>:ColumnText?,
 * ?NO_MORE_COLUMN???,TextField??.
 * TextField?.
 * @see net.sf.jasperreports.engine.export.JRPdfExporter#exportText(net.sf.jasperreports.engine.JRPrintText)
 */
@Override
protected void exportText(JRPrintText text) throws DocumentException {

    JRStyledText styledText = getStyledText(text, false);

    if (styledText == null) {
        return;
    }

    int textLength = styledText.length();

    int x = text.getX() + getOffsetX();
    int y = text.getY() + getOffsetY();
    int width = text.getWidth();
    int height = text.getHeight();
    int topPadding = text.getTopPadding();
    int leftPadding = text.getLeftPadding();
    int bottomPadding = text.getBottomPadding();
    int rightPadding = text.getRightPadding();

    int xFillCorrection = 0;
    int yFillCorrection = 0;

    double angle = 0;

    switch (text.getRotation()) {
    case JRTextElement.ROTATION_LEFT: {
        y = text.getY() + getOffsetY() + text.getHeight();
        xFillCorrection = 1;
        width = text.getHeight();
        height = text.getWidth();
        int tmpPadding = topPadding;
        topPadding = leftPadding;
        leftPadding = bottomPadding;
        bottomPadding = rightPadding;
        rightPadding = tmpPadding;
        angle = Math.PI / 2;
        break;
    }
    case JRTextElement.ROTATION_RIGHT: {
        x = text.getX() + getOffsetX() + text.getWidth();
        yFillCorrection = -1;
        width = text.getHeight();
        height = text.getWidth();
        int tmpPadding = topPadding;
        topPadding = rightPadding;
        rightPadding = bottomPadding;
        bottomPadding = leftPadding;
        leftPadding = tmpPadding;
        angle = -Math.PI / 2;
        break;
    }
    case JRTextElement.ROTATION_UPSIDE_DOWN: {
        x = text.getX() + getOffsetX() + text.getWidth();
        y = text.getY() + getOffsetY() + text.getHeight();
        int tmpPadding = topPadding;
        topPadding = bottomPadding;
        bottomPadding = tmpPadding;
        tmpPadding = leftPadding;
        leftPadding = rightPadding;
        rightPadding = tmpPadding;
        angle = Math.PI;
        break;
    }
    case JRTextElement.ROTATION_NONE:
    default: {
    }
    }

    AffineTransform atrans = new AffineTransform();
    atrans.rotate(angle, x, jasperPrint.getPageHeight() - y);
    pdfContentByte.transform(atrans);

    if (text.getMode() == JRElement.MODE_OPAQUE) {
        Color backcolor = text.getBackcolor();
        pdfContentByte.setRGBColorStroke(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue());
        pdfContentByte.setRGBColorFill(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue());
        pdfContentByte.setLineWidth(1f);
        pdfContentByte.setLineDash(0f);
        pdfContentByte.rectangle(x + xFillCorrection, jasperPrint.getPageHeight() - y + yFillCorrection,
                width - 1, -height + 1);
        pdfContentByte.fillStroke();
    } else {
        /*
         * pdfContentByte.setRGBColorStroke( text.getForecolor().getRed(),
         * text.getForecolor().getGreen(), text.getForecolor().getBlue() );
         * pdfContentByte.setLineWidth(0.1f);
         * pdfContentByte.setLineDash(0f); pdfContentByte.rectangle(
         * text.getX() + offsetX, jasperPrint.getPageHeight() - text.getY() -
         * offsetY, text.getWidth(), - text.getHeight() );
         * pdfContentByte.stroke();
         */
    }

    if (textLength > 0) {
        int horizontalAlignment = Element.ALIGN_LEFT;
        switch (text.getHorizontalAlignment()) {
        case JRAlignment.HORIZONTAL_ALIGN_LEFT: {
            if (text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR) {
                horizontalAlignment = Element.ALIGN_LEFT;
            } else {
                horizontalAlignment = Element.ALIGN_RIGHT;
            }
            break;
        }
        case JRAlignment.HORIZONTAL_ALIGN_CENTER: {
            horizontalAlignment = Element.ALIGN_CENTER;
            break;
        }
        case JRAlignment.HORIZONTAL_ALIGN_RIGHT: {
            if (text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR) {
                horizontalAlignment = Element.ALIGN_RIGHT;
            } else {
                horizontalAlignment = Element.ALIGN_LEFT;
            }
            break;
        }
        case JRAlignment.HORIZONTAL_ALIGN_JUSTIFIED: {
            horizontalAlignment = Element.ALIGN_JUSTIFIED;
            break;
        }
        default: {
            horizontalAlignment = Element.ALIGN_LEFT;
        }
        }

        float verticalOffset = 0f;
        switch (text.getVerticalAlignment()) {
        case JRAlignment.VERTICAL_ALIGN_TOP: {
            verticalOffset = 0f;
            break;
        }
        case JRAlignment.VERTICAL_ALIGN_MIDDLE: {
            verticalOffset = (height - topPadding - bottomPadding - text.getTextHeight()) / 2f;
            break;
        }
        case JRAlignment.VERTICAL_ALIGN_BOTTOM: {
            verticalOffset = height - topPadding - bottomPadding - text.getTextHeight();
            break;
        }
        default: {
            verticalOffset = 0f;
        }
        }

        float llx = x + leftPadding;
        float lly = jasperPrint.getPageHeight() - y - topPadding - verticalOffset - text.getLeadingOffset();
        float urx = x + width - rightPadding;
        float ury = jasperPrint.getPageHeight() - y - height + bottomPadding;

        //?,???
        if (this.jasperMoveXY != null) {
            llx = x + leftPadding + jasperMoveXY.getX();
            lly = jasperPrint.getPageHeight() - y - topPadding - verticalOffset - text.getLeadingOffset()
                    - jasperMoveXY.getY();
            urx = x + width - rightPadding + jasperMoveXY.getX();
            ury = jasperPrint.getPageHeight() - y - height + bottomPadding - jasperMoveXY.getY();
        }

        boolean isOver = false;
        int status = ColumnText.START_COLUMN;
        Phrase phrase = getPhrase(styledText, text);

        ColumnText colText = new ColumnText(pdfContentByte);
        colText.setSimpleColumn(phrase, llx, lly, urx, ury, 0, // text.getLineSpacingFactor(),//
                // *
                // text.getFont().getSize(),
                horizontalAlignment);

        colText.setLeading(0, text.getLineSpacingFactor());// *
        // text.getFont().getSize());
        colText.setRunDirection(
                text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR ? PdfWriter.RUN_DIRECTION_LTR
                        : PdfWriter.RUN_DIRECTION_RTL);

        float yLine = colText.getYLine();

        // ColumnText
        while (colText.hasMoreText(status)) {
            status = colText.go(true);
            colText.setYLine(yLine);

            // ??,true
            if (status == ColumnText.NO_MORE_COLUMN) {
                isOver = true;
                break;
            }
        }

        // ,ColumnText
        if (!isOver) {
            colText.setText(phrase);
            status = ColumnText.START_COLUMN;

            while (colText.hasMoreText(status)) {
                status = colText.go();
                colText.setYLine(yLine);
            }

        } else {
            // TextField,??
            String key = text.getKey();// PdfTextid
            if (alreadyExistFields.contains(key)) { // ?
                key = createUniqueName();
            }
            alreadyExistFields.add(key);
            TextField tf = new TextField(pdfContentByte.getPdfWriter(), new Rectangle(llx, lly, urx, ury), key);
            tf.setAlignment(horizontalAlignment);
            tf.setText(text.getText());
            tf.setFont(PdfUtils.createSongLightBaseFont());

            // styledText ??,?
            if (!text.isStyledText()) {
                tf.setOptions(TextField.MULTILINE);
            }

            try {
                pdfContentByte.getPdfWriter().addAnnotation(tf.getTextField());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    atrans = new AffineTransform();
    atrans.rotate(-angle, x, jasperPrint.getPageHeight() - y);
    pdfContentByte.transform(atrans);

    /*   */
    exportBox(text, text);
}

From source file:org.areasy.common.doclet.document.Index.java

License:Open Source License

/**
 * Creates a simple alphabetical index of all
 * classes and members of the API.//from  w ww .j  a va  2s. c om
 *
 * @throws Exception If the Index could not be created.
 */
public void create() throws Exception {
    if (!DefaultConfiguration.getBooleanConfigValue(ARG_CREATE_INDEX, false)) {
        log.trace("Index creation disabled.");
        return;
    }

    log.trace("Start creating Index...");

    State.setCurrentHeaderType(HEADER_INDEX);
    State.increasePackageChapter();

    // Name of the package (large font)
    pdfDocument.newPage();

    // Create "Index" bookmark
    String label = DefaultConfiguration.getString(ARG_LB_OUTLINE_INDEX, LB_INDEX);
    String dest = "INDEX:";
    Bookmarks.addRootBookmark(label, dest);
    Chunk indexChunk = new Chunk(label, Fonts.getFont(TEXT_FONT, BOLD, 30));
    indexChunk.setLocalDestination(dest);

    Paragraph indexParagraph = new Paragraph((float) 30.0, indexChunk);

    pdfDocument.add(indexParagraph);

    // we grab the ContentByte and do some stuff with it
    PdfContentByte cb = pdfWriter.getDirectContent();
    ColumnText ct = new ColumnText(cb);
    ct.setLeading((float) 9.0);

    float[] right = { 70, 320 };
    float[] left = { 300, 550 };

    // fill index columns with text
    String letter = "";
    Set keys = memberList.keySet();

    // keys must be sorted case unsensitive
    ArrayList sortedKeys = new ArrayList(keys.size());

    // Build sorted list of all entries
    Iterator keysIterator = keys.iterator();
    while (keysIterator.hasNext()) {
        sortedKeys.add(keysIterator.next());
    }
    Collections.sort(sortedKeys, this);

    Iterator realNames = sortedKeys.iterator();

    while (realNames.hasNext()) {
        String memberName = (String) realNames.next();
        String currentLetter = memberName.substring(0, 1).toUpperCase();
        log.trace("Create index entry for " + memberName);

        // Check if next letter in alphabet is reached
        if (currentLetter.equalsIgnoreCase(letter) == false) {
            // If yes, switch to new letter and print it
            letter = currentLetter.toUpperCase();
            Paragraph lphrase = new Paragraph((float) 13.0);
            lphrase.add(new Chunk("\n\n" + letter + "\n", Fonts.getFont(TEXT_FONT, 12)));
            ct.addText(lphrase);
        }

        // Print member name
        Paragraph phrase = new Paragraph((float) 10.0);
        phrase.add(new Chunk("\n" + memberName + "  ", Fonts.getFont(TEXT_FONT, 9)));

        Iterator sortedPages = getSortedPageNumbers(memberName);
        boolean firstNo = true;
        while (sortedPages.hasNext()) {
            Integer pageNo = (Integer) sortedPages.next();
            // Always add 1 to the stored value, because the pages were
            // counted beginning with 0 internally, but their visible
            // numbering starts with 1
            String pageNumberText = String.valueOf(pageNo.intValue() + 1);
            if (!firstNo) {
                phrase.add(new Chunk(", ", Fonts.getFont(TEXT_FONT, 9)));
            }
            phrase.add(new Chunk(pageNumberText, Fonts.getFont(TEXT_FONT, 9)));
            firstNo = false;
        }

        ct.addText(phrase);
    }

    // Now print index by printing columns into document
    int status = 0;
    int column = 0;

    while ((status & ColumnText.NO_MORE_TEXT) == 0) {
        ct.setSimpleColumn(right[column], 60, left[column], 790, 16, Element.ALIGN_LEFT);
        status = ct.go();

        if ((status & ColumnText.NO_MORE_COLUMN) != 0) {
            column++;

            if (column > 1) {
                pdfDocument.newPage();
                column = 0;
            }
        }
    }

    log.trace("Index created.");
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java

License:Open Source License

protected void drawComplexText(final RenderableComplexText node, final Graphics2D g2) {
    try {//from w  w w.  j a v a2 s. c  o  m
        final Phrase p = createPhrase(node);
        final ColumnConfig cc = createColumnText(node);

        final PdfGraphics2D pg2 = (PdfGraphics2D) getGraphics();
        final PdfContentByte cb = pg2.getRawContentByte();
        ColumnText ct = cc.reconfigure(cb, p);
        ct.setText(p);
        if (ct.go(false) == ColumnText.NO_MORE_COLUMN) {
            throw new InvalidReportStateException(
                    "iText signaled an error when printing text. Failing to prevent silent data-loss: Width="
                            + ct.getFilledWidth());
        }
    } catch (DocumentException e) {
        throw new InvalidReportStateException(e);
    }
}

From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java

License:Open Source License

/**
 * The method that renders the PDF file//from   w w w. j a va  2  s . c om
 */
public void addColumnsContentToDocument() {
    // following test required if the [columns: command appears before any text
    if (iTDocument == null || iTColumn == null) {
        return;
    }

    iTStatus = ColumnText.NO_MORE_COLUMN;

    try {
        while (ColumnText.hasMoreText(iTStatus)) {

            if (pdfData.getCurrColumn() >= pdfData.getColumnCount()) {
                iTDocument.newPage();
                pdfData.setCurrColumn(0);
            }

            setColumnSize();

            iTStatus = iTColumn.go();

            if (ColumnText.hasMoreText(iTStatus)) {
                int currCol = pdfData.getCurrColumn();
                pdfData.setCurrColumn(currCol + 1);
            }
        }
    } catch (DocumentException de) { //TODO: Replace with true exception handling
        System.out.println("Exception adding text to iTColumn (ColumnText) in OutfilePdf");
    }
}

From source file:org.sakaiproject.evaluation.tool.reporting.EvalPDFReportBuilder.java

License:Educational Community License

public void addElementArrayWithJump(ArrayList<Element> arrayElements) {
    //20140226 - daniel.merino@unavarra.es - https://jira.sakaiproject.org/browse/EVALSYS-1100
    //Adds an array of elements, jumping to next column/page if there is not space enough.
    //First it tests if current element fits in current column.
    //If it does not fit, we test if it fits in a whole column.
    //If it neither fits, we call another method that adds the array element by element.

    try {//from w ww. j a va 2 s.  co  m
        //First test. Do the elements fit in current column?
        float y = responseArea.getYLine();
        LOG.debug("Vertical position Y: " + y);

        for (Element element : arrayElements) {
            responseArea.addElement(element);
        }

        status = responseArea.go(true); //Add elements in simulation mode to see if there is a column jump or not.

        if (status == ColumnText.NO_MORE_COLUMN) {
            //Element has not fit in the column, a new column is needed.
            column = Math.abs(column - 1);

            if (column == 0) {
                document.newPage();
                responseArea.setSimpleColumn(document.left(), document.top(), document.right() / 2,
                        document.bottom() + pagefooter);
            } else {
                responseArea.setSimpleColumn(document.right() / 2, document.top(), document.right(),
                        document.bottom() + pagefooter);
            }
            //Just to align vertically the top elements
            if (!((Element) arrayElements.get(0)).toString().equals("[ ]"))
                arrayElements.add(0, new Paragraph(" "));

            //Second test: Do the elements fit in a new column?
            responseArea.setText(null);

            y = responseArea.getYLine();
            for (Element element : arrayElements) {
                responseArea.addElement(element);
            }
            status = responseArea.go(true);

            if (status == ColumnText.NO_MORE_COLUMN) {
                responseArea.setYLine(y);
                addBigElementArray(arrayElements);
            } else {
                responseArea.setYLine(y);

                //After testing that they fit, we put the elements in a new column.
                responseArea.setText(null);
                for (Element element : arrayElements) {
                    responseArea.addElement(element);
                }
                responseArea.go();
            }
        } else {
            responseArea.setYLine(y);

            //After testing that they fit, we put the elements in the current column.
            responseArea.setText(null);
            for (Element element : arrayElements) {
                responseArea.addElement(element);
            }
            responseArea.go();
        }

    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        throw UniversalRuntimeException.accumulate(e, "Unable to add elements to PDF Report");
    }
}

From source file:org.sakaiproject.evaluation.tool.reporting.EvalPDFReportBuilder.java

License:Educational Community License

public void addLittleElementWithJump(Element littleElement) {
    //20140226 - daniel.merino@unavarra.es - https://jira.sakaiproject.org/browse/EVALSYS-1100
    //Adds a little element testing if it fits in current column.
    try {/*www  .ja va 2 s. c  om*/
        responseArea.addElement(littleElement);

        status = responseArea.go();
        if (status == ColumnText.NO_MORE_COLUMN) {
            column = Math.abs(column - 1);

            if (column == 0) {
                document.newPage();
                responseArea.setSimpleColumn(document.left(), document.top(), document.right() / 2,
                        document.bottom() + pagefooter);
            } else {
                responseArea.setSimpleColumn(document.right() / 2, document.top(), document.right(),
                        document.bottom() + pagefooter);
            }
        }
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        throw UniversalRuntimeException.accumulate(e, "Unable to add elements to PDF Report");
    }
}