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

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

Introduction

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

Prototype

public void setLeading(float leading) 

Source Link

Document

Sets the leading to fixed.

Usage

From source file:classroom.filmfestival_c.Movies25.java

@SuppressWarnings("unchecked")
public static boolean addText(String s, PdfContentByte canvas, float[] f, float size, boolean simulate)
        throws DocumentException, IOException {
    StyleSheet styles = new StyleSheet();
    styles.loadTagStyle("p", "size", size + "px");
    styles.loadTagStyle("p", "align", "justify");
    styles.loadTagStyle("p", "hyphenation", "en_us");
    ArrayList<Element> objects = HTMLWorker.parseToList(new StringReader(s), styles, null);
    ColumnText ct = new ColumnText(canvas);
    ct.setAlignment(Element.ALIGN_JUSTIFIED);
    ct.setLeading(size * 1.2f);
    ct.setSimpleColumn(f[1] + 2, f[2] + 2, f[3] - 2, f[4]);
    for (Element element : objects) {
        ct.addElement(element);/*from   w ww  .java2  s .  c om*/
    }
    return ColumnText.hasMoreText(ct.go(simulate));
}

From source file:net.sf.jasperreports.engine.export.PdfTextRenderer.java

License:Open Source License

/**
 * //from w  w  w .  j a  v a2 s  . co m
 */
public void draw() {
    TabSegment segment = segments.get(segmentIndex);

    float advance = segment.layout.getAdvance();

    ColumnText colText = new ColumnText(pdfContentByte);
    colText.setSimpleColumn(pdfExporter.getPhrase(segment.as, segment.text, text),
            x + drawPosX + leftOffsetFactor * advance, // + leftPadding
            pdfExporter.getCurrentJasperPrint().getPageHeight() - y - topPadding - verticalAlignOffset
            //- text.getLeadingOffset()
                    + lineHeight - drawPosY,
            x + drawPosX + segment.layout.getAdvance() + rightOffsetFactor * advance, // + leftPadding
            pdfExporter.getCurrentJasperPrint().getPageHeight() - y - topPadding - verticalAlignOffset
            //- text.getLeadingOffset()
                    - 400//+ lineHeight//FIXMETAB
                    - drawPosY,
            0, //text.getLineSpacingFactor(),// * text.getFont().getSize(),
            horizontalAlignment);

    //colText.setLeading(0, text.getLineSpacingFactor());// * text.getFont().getSize());
    colText.setLeading(lineHeight);
    colText.setRunDirection(text.getRunDirectionValue() == RunDirectionEnum.LTR ? PdfWriter.RUN_DIRECTION_LTR
            : PdfWriter.RUN_DIRECTION_RTL);

    try {
        colText.go();
    } catch (DocumentException e) {
        throw new JRRuntimeException(e);
    }
}

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 w w.  j ava 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.");
}