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

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

Introduction

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

Prototype

public void addText(Chunk chunk) 

Source Link

Document

Adds a Chunk to the current text array.

Usage

From source file:com.qcadoo.report.api.pdf.PdfPageNumbering.java

License:Open Source License

private void buildFooter(final PdfWriter writer, final Document document) {
    PdfContentByte cb = writer.getDirectContent();

    cb.saveState();//from w w  w . j  a va2  s. c om

    String text = footer.getPage() + " " + writer.getPageNumber() + " " + footer.getIn() + " ";

    float textBase = document.bottom() - 25;
    float textSize = FontUtils.getDejavu().getWidthPoint(text, 7);

    cb.setColorFill(ColorUtils.getLightColor());
    cb.setColorStroke(ColorUtils.getLightColor());
    cb.setLineWidth(1);
    cb.setLineDash(2, 2, 1);
    cb.moveTo(document.left(), document.bottom() - 10);
    cb.lineTo(document.right(), document.bottom() - 10);
    cb.stroke();
    cb.beginText();
    cb.setFontAndSize(FontUtils.getDejavu(), 7);

    float adjust = FontUtils.getDejavu().getWidthPoint("0", 7);

    cb.setTextMatrix(document.right() - textSize - adjust, textBase);
    cb.showText(text);

    textSize = FontUtils.getDejavu().getWidthPoint(footer.getGeneratedBy(), 7);

    cb.setTextMatrix(document.right() - textSize, textBase - 10);
    cb.showText(footer.getGeneratedBy());

    textSize = FontUtils.getDejavu().getWidthPoint(generationDate, 7);

    cb.setTextMatrix(document.right() - textSize, textBase - 20);
    cb.showText(generationDate);
    cb.endText();

    try {
        textSize = FontUtils.getDejavu().getWidthPoint(footer.getAdditionalText(), 7);

        ColumnText ct = new ColumnText(cb);

        ct.setSimpleColumn(new Phrase(footer.getAdditionalText(), FontUtils.getDejavuRegular7Light()),
                document.left() + 240, textBase + 10, document.left() + 390, textBase - 25, 10,
                Element.ALIGN_LEFT);
        ct.go();
    } catch (DocumentException e) {
        LOG.warn("Problem with additional text generation in report footer.");
    }

    try {
        ColumnText ct = new ColumnText(cb);

        ct.setSimpleColumn(document.left(), textBase + 10, document.left() + 230, textBase - 25, 10,
                Element.ALIGN_LEFT);
        ct.addText(new Phrase(footer.getCompanyName() + "\n", FontUtils.getDejavuRegular7Light()));

        if (!"".equals(footer.getAddress())) {
            ct.addText(new Phrase(footer.getAddress() + "\n", FontUtils.getDejavuRegular7Light()));
        }
        if (!"".equals(footer.getPhoneEmail())) {
            ct.addText(new Phrase(footer.getPhoneEmail(), FontUtils.getDejavuRegular7Light()));
        }

        ct.go();
    } catch (DocumentException e) {
        LOG.warn("Problem with company text generation in report footer.");
    }

    cb.addTemplate(total, document.right() - adjust, textBase);
    cb.restoreState();

}

From source file:corner.orm.tapestry.pdf.components.PdfColumnText.java

License:Apache License

/**
 * ColumnText.//from ww  w  .  j ava 2 s.c  o m
 * 
 * @param ct
 */
@Override
protected void renderColumnText(ColumnText ct, PdfWriterDelegate writer, Document doc) {
    ct.addText(new Phrase(getValue(), PdfUtils.createSongLightFont(0)));
}

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./*  w  w w  .ja v  a  2 s  .co m*/
 *
 * @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.tellervo.desktop.print.CompleteBoxLabel.java

License:Open Source License

public void generateBoxLabel(OutputStream output) {

    try {/*w ww.  j  a va 2s.co  m*/

        PdfWriter writer = PdfWriter.getInstance(document, output);

        document.setPageSize(PageSize.LETTER);
        document.open();

        cb = writer.getDirectContent();

        // Set basic metadata
        document.addAuthor("Peter Brewer");
        document.addSubject("Box Label");

        for (WSIBox b : this.boxlist) {

            // Title Left      
            ColumnText ct = new ColumnText(cb);
            ct.setSimpleColumn(document.left(), document.top(15) - 210, 368, document.top(15), 20,
                    Element.ALIGN_LEFT);
            ct.addText(getTitlePDF(b));
            ct.go();

            // Barcode
            ColumnText ct2 = new ColumnText(cb);
            ct2.setSimpleColumn(370, document.top(15) - 100, document.right(0), document.top(0), 20,
                    Element.ALIGN_RIGHT);
            ct2.addElement(getBarCode(b));
            ct2.go();

            // Timestamp
            ColumnText ct3 = new ColumnText(cb);
            ct3.setSimpleColumn(document.left(), document.top(15) - 223, 350, document.top(15) - 60, 20,
                    Element.ALIGN_LEFT);
            ct3.setLeading(0, 1.2f);
            ct3.addText(getTimestampPDF(b));
            ct3.go();

            // Pad text
            document.add(new Paragraph(" "));
            Paragraph p2 = new Paragraph();
            p2.setSpacingBefore(70);
            p2.setSpacingAfter(10);
            p2.add(new Chunk(" ", bodyFontLarge));
            document.add(new Paragraph(p2));

            // Ring samples table
            addTable(b);
            document.add(getParagraphSpace());

            document.add(getComments(b));

            document.newPage();

        }

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }

    // Close the document
    document.close();
}

From source file:org.tellervo.desktop.print.ProSheet.java

License:Open Source License

private void generateProSheet(OutputStream output) {

    Paragraph spacingPara = new Paragraph();
    spacingPara.setSpacingBefore(10);/*from w  w w  .  j a va  2 s.com*/
    spacingPara.add(new Chunk(" ", bodyFont));

    try {

        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.setPageSize(PageSize.LETTER);

        // Set basic metadata
        document.addAuthor("Peter Brewer");
        document.addSubject("Corina Provenience Sheet for " + o.getTitle());

        HeaderFooter footer = new HeaderFooter(new Phrase(""), new Phrase(""));
        footer.setAlignment(Element.ALIGN_RIGHT);
        footer.setBorder(0);
        document.setFooter(footer);

        HeaderFooter header = new HeaderFooter(new Phrase(o.getLabCode() + " - " + o.getTitle(), bodyFont),
                false);
        header.setAlignment(Element.ALIGN_RIGHT);
        header.setBorder(0);
        document.setHeader(header);

        document.open();
        cb = writer.getDirectContent();

        // Title Left      
        ColumnText ct = new ColumnText(cb);
        ct.setSimpleColumn(document.left(), document.top() - 193, document.right(), document.top() - 20, 20,
                Element.ALIGN_LEFT);
        ct.addText(getTitlePDF());
        ct.go();

        // Timestamp
        ColumnText ct3 = new ColumnText(cb);
        ct3.setSimpleColumn(document.left(), document.top() - 223, 283, document.top() - 60, 20,
                Element.ALIGN_LEFT);
        ct3.setLeading(0, 1.2f);
        ct3.addText(getTimestampPDF());
        ct3.go();

        // Pad text
        document.add(spacingPara);
        document.add(getObjectDescription());
        document.add(getObjectComments());

        document.add(spacingPara);

        getElementTable();

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }

    // Close the document
    document.close();
}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

private void generateSeriesReport(OutputStream output) {

    displayUnits = NormalTridasUnit/*  www .  j  av a2  s .  c om*/
            .valueOf(App.prefs.getPref(PrefKey.DISPLAY_UNITS, NormalTridasUnit.MICROMETRES.name().toString()));

    try {

        PdfWriter writer = PdfWriter.getInstance(document, output);
        document.setPageSize(PageSize.LETTER);
        document.open();
        cb = writer.getDirectContent();

        // Set basic metadata
        document.addAuthor("Peter Brewer");
        document.addSubject("Tellervo Series Report for " + s.getDisplayTitle());

        // Title Left      
        ColumnText ct = new ColumnText(cb);
        ct.setSimpleColumn(document.left(), document.top() - 163, 283, document.top(), 20, Element.ALIGN_LEFT);
        ct.addText(getTitlePDF());
        ct.go();

        // Barcode
        ColumnText ct2 = new ColumnText(cb);
        ct2.setSimpleColumn(370, document.top(15) - 100, document.right(0), document.top(0), 20,
                Element.ALIGN_RIGHT);
        ct2.addElement(getBarCode());
        ct2.go();

        // Timestamp
        ColumnText ct3 = new ColumnText(cb);
        ct3.setSimpleColumn(document.left(), document.top() - 223, 283, document.top() - 60, 20,
                Element.ALIGN_LEFT);
        ct3.setLeading(0, 1.2f);
        ct3.addText(getTimestampPDF());
        ct3.go();

        // Authorship
        ColumnText ct4 = new ColumnText(cb);
        ct4.setSimpleColumn(284, document.top() - 223, document.right(10), document.top() - 60, 20,
                Element.ALIGN_RIGHT);
        ct4.setLeading(0, 1.2f);
        ct4.addText(getAuthorshipPDF());
        ct4.go();

        // Pad text
        document.add(new Paragraph(" "));
        Paragraph p2 = new Paragraph();
        p2.setSpacingBefore(50);
        p2.setSpacingAfter(10);
        p2.add(new Chunk(" ", bodyFont));
        document.add(new Paragraph(p2));

        // Ring width table
        getRingWidthTable();
        document.add(getParagraphSpace());

        if (s.getSeries() instanceof TridasMeasurementSeries) {
            // MEASUREMENT SERIES

            //document.add(getRingRemarks());
            document.add(getWoodCompletenessPDF());
            document.add(getParagraphSpace());
            document.add(getSeriesComments());
            document.add(getParagraphSpace());
            document.add(getInterpretationPDF());
            document.add(getParagraphSpace());
            document.add(getElementAndSampleInfo());
        } else {
            // DERIVED SERIES
            getWJTable();
            document.add(getParagraphSpace());
            document.add(getSeriesComments());
            document.add(getParagraphSpace());
            //document.add(getRingRemarks());

        }

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }

    // Close the document
    document.close();
}

From source file:oscar.oscarPrevention.pageUtil.PreventionPrintPdf.java

License:Open Source License

private boolean checkColumnFill(ColumnText ct, String preventionHeader, Font font, boolean pageBreak) {
    if (linesWritten + linesToBeWritten > maxLines) {

        //reset upperYcoord for pages 2 and above
        if (curPage == 1 && pageBreak) {
            upperYcoord = document.top() - font.getCalculatedLeading(LINESPACING);
            pageHeight = upperYcoord - document.bottom();
            maxLines = (int) Math.floor(pageHeight / (font.getCalculatedLeading(LINESPACING) + 4d));
            numPages = (int) Math.ceil(((double) numLines - totalLinesWritten) / ((double) maxLines * NUMCOLS))
                    + 1;/*ww w  .  ja  v  a2 s.c  o m*/
        }
        pageBreak = breakPage(pageBreak, upperYcoord);
        linesWritten = 0;
        if (preventionHeader.length() > 0) {
            Phrase procHeaderContd = new Phrase(LEADING, "Prevention " + preventionHeader + " cont'd\n", font);
            ct.addText(procHeaderContd);
            ++linesToBeWritten;
        }

    }

    return pageBreak;
}

From source file:questions.stamppages.StampAndAddColumns.java

public static void main(String[] args) {
    try {/*from  ww w  .j a  v  a  2 s .c  om*/
        PdfReader reader = new PdfReader(RESOURCE);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        AcroFields form = stamper.getAcroFields();
        form.setField("Who", "world");
        ColumnText ct = new ColumnText(stamper.getOverContent(1));
        String line;
        Phrase p;
        BufferedReader br = new BufferedReader(new FileReader(TXT));
        while ((line = br.readLine()) != null) {
            p = new Phrase(line + "\n");
            ct.addText(p);
        }
        int status = ColumnText.START_COLUMN;
        ct.setSimpleColumn(100, 700, 495, 100);
        status = ct.go();
        int pageCt = 1;
        while (ColumnText.hasMoreText(status)) {
            stamper.insertPage(++pageCt, reader.getPageSize(1));
            ct.setYLine(700);
            ct.setCanvas(stamper.getOverContent(pageCt));
            status = ct.go();
        }
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}