Example usage for com.lowagie.text Chunk Chunk

List of usage examples for com.lowagie.text Chunk Chunk

Introduction

In this page you can find the example usage for com.lowagie.text Chunk Chunk.

Prototype

public Chunk(DrawInterface separator) 

Source Link

Document

Creates a separator Chunk.

Usage

From source file:org.pz.platypus.plugin.pdf.commands.PdfEoParagraph.java

License:Open Source License

public int process(final IOutputContext context, final Token tok, final int tokNum) {
    if (context == null) {
        throw new IllegalArgumentException();
    }//from  w w  w. j  a  v a 2 s . c  o  m

    PdfData pdf = (PdfData) context;

    // if we're in an paragraph with content, then close it and start a new one.
    // If we're not, it's likely because someone has inserted multiple blank lines,
    // so we just skip a line.
    Paragraph currPar = pdf.getOutfile().getItPara();
    //        if( currPar == null || ! currPar.isEmpty() ) {
    if (currPar == null || currPar.size() > 0) {
        pdf.getOutfile().startNewParagraph();
    } else {
        currPar.add(new Chunk(Chunk.NEWLINE));
    }
    return 0;

}

From source file:org.pz.platypus.plugin.pdf.commands.PdfHardCR.java

License:Open Source License

public int process(final IOutputContext context, final Token tok, final int tokNum) {
    if (context == null || tok == null) {
        throw new IllegalArgumentException();
    }//from ww  w .  j  a va  2s. co  m

    PdfData pdd = (PdfData) context;
    PdfOutfile outfile = pdd.getOutfile();
    if (outfile == null) {
        return (0); //TODO: Error message, though effectively an impossible error.
    }

    // a [] marks the end of a bullet entry. If the entry is a paragraph, (almost always the case)
    // then add it to the current list and return.
    Paragraph currPar = pdd.getOutfile().getItPara();
    if (outfile.inABulletList()) {
        if (currPar != null && !currPar.isEmpty()) {
            outfile.addParagraphToList(currPar);
            return (0);
        }
    }

    currPar.add(new Chunk(Chunk.NEWLINE));

    // if it's the first token in line, it = a blank line, so an additional
    // NEWLINE needs to be emitted, unless it's right after an end of listing command,
    // which has already emitted the extra CR/LF.

    if (isFirstTokenInLine(context, tok, tokNum) && !isAfterCodeListing(context, tokNum) && currPar != null) {
        currPar.add(new Chunk(Chunk.NEWLINE));
    }
    return 0;
}

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

License:Open Source License

/**
 * Converts bullet string into an iText Chunk and calls the method that
 * adds a list using the Chunk to define the bullet symbol.
 *
 * @param bulletSymbol string to use as a bullet symbol (most often, a single character)
 *//* w w  w .jav a  2s . c o  m*/
public void startPlainBulletList(final String bulletSymbol) {
    String bullet = bulletSymbol;
    if (bullet == null || bullet.isEmpty()) {
        bullet = DefaultValues.BULLET;
    }

    startPlainBulletList(new Chunk(bullet));
}

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

License:Open Source License

/**
 * Adds a new bullet list to the stack of bulleted lists. (These are saved in a stack because
 * lists can nest)./*  w  w  w.  ja  va2 s  .  c  o  m*/
 *
 * @param bulletSymbol symbol to be used as the bullet marker (an iText Chunk)
 */
public void startPlainBulletList(final Chunk bulletSymbol) {
    // set the skip to 0 lines, output old text, start a new paragraph.
    float initialParaSkip = pdfData.getParagraphSkip();
    int initialParaSkipSource = pdfData.getParagraphSkipLine();
    pdfData.setParagraphSkip(0f, new Source(0, initialParaSkipSource));
    startNewParagraph();

    // then reset the paragraph skip to the previous value.
    pdfData.setParagraphSkip(initialParaSkip, new Source(0, initialParaSkipSource));

    // create the bullet list
    Chunk bulletMarker = bulletSymbol;
    float indentMargin = 18f; // for the nonce, all indents are 1/4"

    List bulletList = new List(List.UNORDERED, indentMargin);
    if (bulletMarker == null || bulletMarker.isEmpty()) {
        bulletMarker = new Chunk(DefaultValues.BULLET);
    }
    bulletList.setListSymbol(bulletMarker);
    bulletLists.add(bulletList);
}

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

License:Open Source License

/**
 * Implement the line spacing before the paragraph, if any.
 *
 * Note: We do this manually rather than call Paragraph.setSpacingBefore() in iText
 * because setSpacingBefore() in iText affects the current paragraph. So is [paraskip=0]
 * occurs midway in a paragraph, that pargraph will have 0 spacing before it, rather than
 * the previous paraskip value, which was in effect when the paragraph was started. 2009-01-31
 *
 * @param para the paragraph to align/*  w  ww .j a  v  a 2s .c  o m*/
 * @param pData the PdfData container holding the current settings of the PDF output
 */
void doParagraphSpaceBefore(final Paragraph para, final PdfData pData) {
    float skipLines = pData.getParagraphSkip();

    // add 1, as you need 2 NEWLINES for the first line's skip.
    skipLines++;
    while (skipLines-- > 0) {
        para.add(new Chunk(Chunk.NEWLINE));
    }
}

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

License:Open Source License

/**
 * Blank iText paragraph used for padding 
 * @return Paragraph/* w  w w  .j a  va 2s. c om*/
 */
protected Paragraph getParagraphSpace() {
    Paragraph p = new Paragraph();

    p.add(new Chunk(" "));
    return p;
}

From source file:questions.objects.DifferentLeadings.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A7);
    try {//from  w ww.ja  va2 s .  c  o  m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        Chunk space = new Chunk(' ');
        String text = "Quick brown fox jumps over the lazy dog.";
        Phrase phrase1 = new Phrase(text, new Font(Font.HELVETICA, 12));
        Phrase phrase2 = new Phrase(new Chunk(text, new Font(Font.TIMES_ROMAN, 24)));
        Phrase phrase3 = new Phrase(text, new Font(Font.COURIER, 8));
        Phrase phrase4 = new Phrase(text, new Font(Font.HELVETICA, 4));
        Paragraph paragraph = new Paragraph();
        paragraph.add(phrase1);
        paragraph.add(space);
        paragraph.add(phrase2);
        paragraph.add(space);
        paragraph.add(phrase3);
        paragraph.add(space);
        paragraph.add(phrase4);
        paragraph.setMultipliedLeading(1.5f);
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        ColumnText column = new ColumnText(writer.getDirectContent());
        column.setSimpleColumn(document.left(), document.bottom(), document.right(), document.top());
        column.addElement(paragraph);
        column.go();
        document.newPage();
        document.add(paragraph);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:questions.objects.NestingLists.java

public static void main(String[] args) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(RESULT));
    document.open();//from   w  w w  . j ava2 s . c  om
    List list1 = new List(List.ORDERED, 20);
    list1.add(new ListItem(new Chunk("Level 1 - Item 1")));
    list1.add(new ListItem(new Chunk("Level 1 - Item 2")));
    list1.add(new ListItem(new Chunk("Level 1 - Item 3")));

    List list2 = new List(List.ORDERED, 20);
    list2.add(new ListItem(new Chunk("Level 2 - Item 1")));
    list2.add(new ListItem(new Chunk("Level 2 - Item 2")));

    List list3 = new List(List.ORDERED, 20);
    list3.add(new ListItem(new Chunk("Level 3 - Item 1")));
    list3.add(new ListItem(new Chunk("Level 3 - Item 2")));
    list3.add(new ListItem(new Chunk("Level 3 - Item 3")));
    list3.add(new ListItem(new Chunk("Level 3 - Item 4")));
    list2.add(list3);

    list1.add(list2);
    list1.add(new ListItem(new Chunk("Level 1 - Item 4")));

    document.add(list1);
    document.close();
}

From source file:questions.separators.DottedGlue.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*  w ww  .j a v  a2 s.c  om*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();

        PdfContentByte canvas = writer.getDirectContent();
        canvas.moveTo(document.left(), document.top());
        canvas.lineTo(document.left(), 550);
        canvas.moveTo(document.right(), document.top());
        canvas.lineTo(document.right(), 550);
        canvas.stroke();

        Chunk separator = new Chunk(new DottedLineSeparator());

        // two parts
        Paragraph p1 = new Paragraph();
        p1.add(new Chunk("Chapter 1"));
        p1.add(separator);
        p1.add(new Chunk("p 10"));

        // 3 parts
        Paragraph p2 = new Paragraph();
        p2.add(new Chunk("Chapter 2"));
        p2.add(separator);
        p2.add(new Chunk("x"));
        p2.add(separator);
        p2.add(new Chunk("y"));

        // line ends with separator
        Paragraph p3 = new Paragraph();
        p3.add(new Chunk("Chapter 3"));
        p3.add(separator);

        // line starts with a separator
        Paragraph p4 = new Paragraph();
        p4.add(separator);
        p4.add(new Chunk("chapter 4"));

        // line IS a separator
        Paragraph p5 = new Paragraph();
        p5.add(separator);

        // line IS a separator + leading
        Paragraph p6 = new Paragraph(40);
        p6.add(separator);

        // separator galore
        Paragraph p7 = new Paragraph();
        p7.setAlignment(Element.ALIGN_JUSTIFIED);
        for (int i = 0; i < 10; i++) {
            p7.add(new Chunk("This is a test hippopotamus hippopotamus"));
            if (i % 4 == 0)
                p7.add(" hippopotamus hippopotamus hippopotamus hippopotamus");
            p7.add(separator);
        }

        document.add(p1);
        document.add(p1);
        document.add(p2);
        document.add(p3);
        document.add(p4);
        document.add(p5);
        document.add(p6);
        document.add(p7);

        ColumnText ct = new ColumnText(writer.getDirectContent());
        ct.addElement(p1);
        ct.addElement(p1);
        ct.addElement(p2);
        ct.addElement(p3);
        ct.addElement(p4);
        ct.addElement(p5);
        ct.addElement(p6);
        ct.addElement(p7);
        ct.setSimpleColumn(36, 36, 436, 536);
        ct.go();
        canvas.rectangle(36, 36, 400, 500);
        canvas.stroke();
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:questions.separators.LineSeparator1.java

public static void main(String[] args) {
    Document document = new Document();
    try {// w w  w . ja v  a 2s .  c om
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();

        Paragraph separator = new Paragraph(0);
        separator.add(new Chunk(new LineSeparator(1, 80, Color.RED, Element.ALIGN_LEFT, -2)));

        ColumnText column = new ColumnText(writer.getDirectContent());
        for (int i = 0; i < 5; i++) {
            column.addElement(StarSeparators.TEXT);
            column.addElement(separator);
        }
        column.setSimpleColumn(36, 36, 295, 806);
        column.go();
        column.setSimpleColumn(300, 36, 559, 806);
        column.go();
        document.newPage();

        for (int i = 0; i < 10; i++) {
            document.add(StarSeparators.TEXT);
            document.add(separator);
        }
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}