Example usage for com.itextpdf.text Paragraph Paragraph

List of usage examples for com.itextpdf.text Paragraph Paragraph

Introduction

In this page you can find the example usage for com.itextpdf.text Paragraph Paragraph.

Prototype

public Paragraph() 

Source Link

Document

Constructs a Paragraph.

Usage

From source file:com.kohmiho.mpsr.export.PDFGenerator.java

private void addSectionTitle(Document document, String sectionTitle, Font fontChapterHeader, int indentation,
        int spacingBefore, int spacingAfter) throws DocumentException {
    Paragraph paragraph = new Paragraph();
    paragraph.setSpacingBefore(spacingBefore);
    paragraph.setSpacingAfter(spacingAfter);
    paragraph.setIndentationLeft(indentation);
    paragraph.setFont(fontChapterHeader);
    paragraph.add(new Phrase(sectionTitle));
    document.add(paragraph);//ww  w.ja  va2  s.  c om
}

From source file:com.kohmiho.mpsr.export.PDFGenerator.java

private void addParagraph(Document document, PdfWriter writer, XMLWorkerHelper xmlWorker, String data,
        Font font, int indentationLeft, int spacingBefore, int spacingAfter)
        throws DocumentException, IOException {

    if (!data.startsWith("<")) {
        Paragraph paragraph = new Paragraph();
        paragraph.setIndentationLeft(indentationLeft);
        paragraph.setSpacingBefore(spacingBefore);
        paragraph.setSpacingAfter(spacingAfter);
        if (null != font)
            paragraph.setFont(font);//from  w w  w  .jav  a  2s  .  com

        paragraph.add(data);
        document.add(paragraph);
    } else {
        xmlWorker.parseXHtml(writer, document, new StringReader(data));
    }
}

From source file:com.kohmiho.mpsr.export.PDFGenerator.java

private void addImage(Document document, String filename, String caption, Font font, int indentationLeft,
        int spacingBefore, int spacingAfter)
        throws BadElementException, MalformedURLException, IOException, DocumentException {

    if (null == filename) {
        addParagraph(document, null, null, String.format("[*** No Picture for %s ***]", caption), font,
                indentationLeft, 0, 0);//from  w  w w.j  a  va  2 s  .co  m
        return;
    }

    try {
        Paragraph paragraph = new Paragraph();
        paragraph.setIndentationLeft(indentationLeft);
        paragraph.setSpacingBefore(spacingBefore);
        paragraph.setSpacingAfter(spacingAfter);
        if (null != font)
            paragraph.setFont(font);
        paragraph.setKeepTogether(true);
        paragraph.setAlignment(Element.ALIGN_CENTER);

        Image image = Image.getInstance(filename);
        image.scaleToFit(400, 400);

        paragraph.add(new Chunk(image, 0, 0, true));
        paragraph.add(new Chunk("\n"));
        paragraph.add(caption);
        document.add(paragraph);
    } catch (Exception e) {
        addParagraph(document, null, null, String.format("[*** Unable to render picture for %s ***]", caption),
                font, indentationLeft, 0, 0);
    }
}

From source file:com.lawyer.pdfgeneration.AddParagraph.java

public void addNewParagraph(Document document, Font smallBold) throws DocumentException {
    // TODO Auto-generated method stub

    Paragraph preface = new Paragraph();
    // We add one empty line
    // Lets write a big header
    //addEmptyLine(preface, 27);

    String SomeDataWhichIsDerived = pdfReaderFunction.rep1;
    // preface.add(new Paragraph("Generated Path of file"+OUTPUTFILE, catFont));
    //The new paragraph allows us to set the font of our choice
    //addEmptyLine(preface, 5);
    // Will create: Report generated by: _name, _date
    //  preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3smallBold));
    //  addEmptyLine(preface, 20);

    preface.add(new Paragraph(SomeDataWhichIsDerived, smallBold));
    // addEmptyLine(preface, 25);

    //  preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",redFont));

    document.add(preface);//  w  ww  .  j a  va 2 s  . com
    // Start a new page

    document.newPage();

}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

private Paragraph getParagraph(Map it) throws Exception {
    Paragraph p = new Paragraph();
    String lb = MapUtil.getStr(it, "label", null);
    if (lb != null) {
        Chunk ch = new Chunk();
        ch.setLocalDestination(lb);/*from   w  w w  . j a va2  s .  c o m*/
        p.add(ch);
    }
    getChunks(p, it, null);
    List<Map> lst = (List) it.get("items");
    if (lst != null) {
        for (Map item : lst) {
            Element el = getElement(item);
            if (el != null)
                p.add(el);
        }
    }
    applyFont(p, it);

    return p;
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

private com.itextpdf.text.List getList(Map row) throws Exception {
    String type = (String) row.get("type");
    com.itextpdf.text.List list = null;
    if ("greek".equals(type))
        list = new GreekList();
    else if ("roman".equals(type))
        list = new RomanList();
    else if ("zd".equals(type))
        list = new ZapfDingbatsList(1);
    else if ("zd#".equals(type))
        list = new ZapfDingbatsNumberList(1);
    else// w  ww  . j a v  a  2 s  .  co  m
        list = new com.itextpdf.text.List();

    Integer charNumber = (Integer) row.get("charNumber");
    if (charNumber != null) {
        if (list instanceof ZapfDingbatsList) {
            ((ZapfDingbatsList) list).setCharNumber(charNumber);
        }
        if (list instanceof ZapfDingbatsNumberList) {
            ((ZapfDingbatsNumberList) list).setType(charNumber);
        }
    }
    Boolean lowercase = (Boolean) row.get("lowercase");
    if (lowercase != null)
        list.setLowercase(lowercase);
    Boolean numbered = (Boolean) row.get("numbered");
    if (numbered != null)
        list.setNumbered(numbered);
    Boolean lettered = (Boolean) row.get("lettered");
    if (lettered != null)
        list.setLettered(lettered);
    Integer first = (Integer) row.get("first");
    if (first != null)
        list.setFirst(first);
    String symbol = (String) row.get("symbol");
    if (symbol != null) {
        Paragraph p = new Paragraph();
        getChunks(p, row, symbol);
        if (p.size() > 0) {
            Object sym = p.get(0);
            if (sym instanceof Chunk) {
                list.setListSymbol((Chunk) sym);
            }
        }
    }
    Float ident = (Float) row.get("ident");
    if (ident == null)
        ident = 10f;
    list.setSymbolIndent(ident);
    List<Map> lst = (List) row.get("items");
    if (lst != null) {
        for (Map item : lst) {
            Element el = getElement(item);
            if (el != null) {
                ListItem li = new ListItem();
                li.add(el);
                list.add(li);
            }
        }
    }
    if (list.size() > 0) {
        Object o = list.getItems().get(0);
        if (o instanceof Paragraph) {
            Paragraph p = (Paragraph) o;
            Float spaceBefore = (Float) row.get("spaceBefore");
            if (spaceBefore != null)
                p.setSpacingBefore(spaceBefore);
        }
        o = list.getItems().get(list.getItems().size() - 1);
        if (o instanceof Paragraph) {
            Paragraph p = (Paragraph) o;
            Float spaceAfter = (Float) row.get("spaceAfter");
            if (spaceAfter != null)
                p.setSpacingAfter(spaceAfter);
        }
    }
    return list;
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

/**
 * Adds a new line to the currentParagraph.
 * @since 5.0.6//from   w w  w . j  a va 2  s. co m
 */
public void newLine() {
    if (currentParagraph == null) {
        currentParagraph = new Paragraph();
    }
    currentParagraph.add(createChunk("\n"));
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

/**
 * Stacks the current paragraph, indicating that we're starting
 * a new span./* www  .  j  ava 2  s.com*/
 * @since 5.0.6
 */
public void flushContent() {
    pushToStack(currentParagraph);
    currentParagraph = new Paragraph();
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

/**
 * Adds a link to the current paragraph.
 * @since 5.0.6//from w  w w.ja va 2  s .com
 */
public void processLink() {
    if (currentParagraph == null) {
        currentParagraph = new Paragraph();
    }
    // The link provider allows you to do additional processing
    LinkProcessor i = (LinkProcessor) providers.get(HTMLWorker.LINK_PROVIDER);
    if (i == null || !i.process(currentParagraph, chain)) {
        // sets an Anchor for all the Chunks in the current paragraph
        String href = chain.getProperty(HtmlTags.HREF);
        if (href != null) {
            for (Chunk ck : currentParagraph.getChunks()) {
                ck.setAnchor(href);
            }
        }
    }
    // a link should be added to the current paragraph as a phrase
    if (stack.isEmpty()) {
        // no paragraph to add too, 'a' tag is first element
        Paragraph tmp = new Paragraph(new Phrase(currentParagraph));
        currentParagraph = tmp;
    } else {
        Paragraph tmp = (Paragraph) stack.pop();
        tmp.add(new Phrase(currentParagraph));
        currentParagraph = tmp;
    }
}

From source file:com.microware.intrahealth.Createpdf2.java

private static void addTitlePage(Document document) throws DocumentException {

    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from w w w  .  j av a 2  s .  c o  m
    // Lets write a big header
    preface.add(new Paragraph("Break Even Master Input", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Community profile", subFont));
    //      addEmptyLine(preface, 3);
    //      preface.add(new Paragraph("This document describes something which is very important ",
    //            smallBold));
    //
    //      addEmptyLine(preface, 8);
    //
    //      preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}