Example usage for com.lowagie.text List List

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

Introduction

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

Prototype

public List(boolean numbered, boolean lettered, float symbolIndent) 

Source Link

Document

Creates a list

Usage

From source file:FirstPdf.java

private static void createList(Section subCatPart) {
    List list = new List(true, false, 10);
    list.add(new ListItem("First point"));
    list.add(new ListItem("Second point"));
    list.add(new ListItem("Third point"));
    subCatPart.add(list);//w  ww.  j a v  a  2s  . c om
}

From source file:com.aryjr.nheengatu.pdf.PDFDocument.java

License:Open Source License

private void extractVisibleComponents(final Tag tag, final Document doc, final MultiColumnText mct,
        final Paragraph paragraph, final List list) throws DocumentException {
    final Iterator tags = tag.tags();
    Object component;/* ww w  .j a  v a  2 s  .c  o  m*/
    Image image;
    PDFTable table;
    final TagsManager tm = TagsManager.getInstance();

    PDFDocument.log.info("extractVisibleComponents");
    // PDFDocument.log.info(tm.states.size());
    // PDFDocument.log.info(tm.getTextIndent());
    // if (paragraph != null)
    // PDFDocument.log.info(paragraph.getFirstLineIndent());

    while (tags.hasNext()) {
        component = tags.next();
        if (component instanceof Text) {
            System.out.println("Processamento: Iniciou while -> if instanceof text");
            String s = ((Text) component).getText();
            if (s.contains("\\\"")) {
                s = s.replace("\\\"", "\"");
                ((Text) component).setText(s);
            }
            PDFDocument.log.info("text: " + ((Text) component).getText());
            // PDFDocument.log.info(tm.states.size());
            // PDFDocument.log.info(tm.getTextIndent());
            // PDFDocument.log.info(tm.getSpacingBefore());
            // PDFDocument.log.info(tm.getSpacingAfter());

            // If it's a text, create a iText text component for it
            if (paragraph != null)
                paragraph.add(PDFText.createChunk((Text) component));
            else if (list != null)
                list.add(PDFText.createParagraph((Text) component, tm));
            else
                mct.addElement(PDFText.createParagraph((Text) component, tm));
            System.out.println("Processamento: terminou while -> if instanceof text");
        } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("br")) {
            // PDFDocument.log.info("br");
            // PDFDocument.log.info(tm.states.size());
            // PDFDocument.log.info(tm.getTextIndent());

            // If it's a HTML line break
            if (paragraph == null) {
                mct.addElement(new Paragraph("\n"));
            } else {
                paragraph.add("\n");
            }
            System.out.println("Processamento: Iniciou while -> if instanceof tag br");
        } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("p")) {
            // If it's a HTML paragraph, create a iText paragraph for it

            tm.checkTag((Tag) component);
            final Paragraph p = PDFText.createParagraph(null, tm);

            PDFDocument.log.info("p");
            PDFDocument.log.info(tm.getFont().getSize());
            PDFDocument.log.info(p.getLeading());
            // PDFDocument.log.info(tm.states.size());
            // PDFDocument.log.info(tm.getTextIndent());
            // PDFDocument.log.info("align:");
            // PDFDocument.log.info(((Tag)
            // component).getPropertyValue("align"));
            // PDFDocument.log.info(tm.getAlign());

            // Paragraph p = new Paragraph();
            // p.setAlignment(tm.getAlign());
            // p.setKeepTogether(true);
            // // float b = tm.getSpacingBefore();
            // // float a = tm.getSpacingAfter();
            // p.setSpacingBefore(tm.getSpacingBefore());
            // p.setSpacingAfter(tm.getSpacingAfter());
            // p.setFirstLineIndent(tm.getTextIndent());
            extractVisibleComponents((Tag) component, doc, mct, p, list);
            if (paragraph != null)
                paragraph.add(p);
            else
                mct.addElement(p);

            // String align = ((Tag) component).getPropertyValue("align");
            // if (align != null) {
            // p.setAlignment(align.toLowerCase());
            // }
            tm.back();
            System.out.println("Processamento: Iniciou while -> if instanceof tag p");
        } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("ol")) {
            // If it's a HTML paragraph, create a iText paragraph for it
            tm.checkTag((Tag) component);
            if (tm.getListStyleType() == null) {
                ((GraphicsState) tm.states.get(tm.states.size() - 1)).setListStyleType("upper-roman");
            } else if (tm.getListStyleType().equals("upper-roman")) {
                ((GraphicsState) tm.states.get(tm.states.size() - 1)).setListStyleType("lower-alpha");
            }
            final List l = new RomanList(tm.getListStyleType(), 30);
            if (list != null)
                list.add(l);
            else
                mct.addElement(l);
            extractVisibleComponents((Tag) component, doc, mct, null, l);
            tm.back();
            System.out.println("Processamento: Iniciou while -> if instanceof tag ol");
        } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("ul")) {
            // If it's a HTML paragraph, create a iText paragraph for it
            final List l = new List(false, false, 20.0f);
            tm.checkTag((Tag) component);
            if (paragraph != null)
                paragraph.add(l);
            else
                mct.addElement(l);
            extractVisibleComponents((Tag) component, doc, mct, null, l);
            tm.back();
            System.out.println("Processamento: Iniciou while -> if instanceof tag ul");
        } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("li")) {
            // If it's a HTML paragraph, create a iText paragraph for it
            final ListItem li = new ListItem(tm.getFont().getSize() * 1.25f);
            li.setSpacingAfter(tm.getFont().getSize() * 0.5f);

            PDFDocument.log.info("li");
            PDFDocument.log.info(tm.getFont().getSize());
            PDFDocument.log.info(li.getLeading());

            tm.checkTag((Tag) component);
            if (list == null)
                mct.addElement(li);
            else
                list.add(li);
            extractVisibleComponents((Tag) component, doc, mct, li, list);
            tm.back();
        } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("img")) {
            // If it's a HTML image, create a iText image component for it
            try {
                // TODO the image path can't be static
                image = PDFImage.createImage((Tag) component);
                if (paragraph == null) {
                    mct.addElement(image);
                } else {
                    paragraph.add(image);
                }
            } catch (final Exception e) {
                e.printStackTrace();
            }
            System.out.println("Processamento: Iniciou while -> if instanceof tag img");
        } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("table")) {
            // If it's a HTML table, create a iText table component for it
            try {
                table = PDFTable.createTable((Tag) component);
                mct.addElement(table);
            } catch (final Exception e) {
                e.printStackTrace();
            }
        } else if (component instanceof Tag && ((Tag) component).getName().equalsIgnoreCase("div")) {
            final String s = ((Tag) component).getPropertyValue("style");
            if (s != null && s.equals("PAGE-BREAK-AFTER: always")) {
                doc.add(mct);
                mct.nextColumn();
            }
            tm.checkTag((Tag) component);
            extractVisibleComponents((Tag) component, doc, mct, paragraph, list);
            tm.back();
            System.out.println("Processamento: Iniciou while -> if instanceof tag div");
        } else {
            // If it's an another tag, check the name and call this method
            // again

            // PDFDocument.log.info("other!");
            // PDFDocument.log.info(tm.states.size());
            // PDFDocument.log.info(tm.getTextIndent());

            tm.checkTag((Tag) component);
            extractVisibleComponents((Tag) component, doc, mct, paragraph, list);
            tm.back();
            System.out.println("Processamento: Iniciou while -> else if");
        }
    }
}

From source file:org.areasy.common.doclet.document.tags.TagOL.java

License:Open Source License

public Element[] openTagElements() {
    char typeChar = getTypeChar();
    int first = getFirstListIndex();

    switch (typeChar) {
    case 'a':
    case 'A':
        list = new List(false, true, 20);
        if (first > 0 && first <= 26)
            list.setFirst((char) (typeChar + (first - 1)));
        break;//from  w  w w  . j a  v a 2s .  c  o m

    case 'i':
    case 'I':
        list = new RomanList(typeChar == 'i', 20);
        if (first > 0)
            list.setFirst(first);
        break;

    case '1':
    default:
        list = new List(true, 20);
        if (first > 0)
            list.setFirst(first);
    }

    list.setListSymbol(new Chunk("", getFont()));

    Element[] elements = new Element[1];
    elements[0] = new Paragraph((float) 8.0, " ", getFont());

    return elements;
}