Example usage for com.lowagie.text Section add

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

Introduction

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

Prototype

public boolean add(Object o) 

Source Link

Document

Adds a Paragraph, List, Table or another Section to this Section.

Usage

From source file:FirstPdf.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");
    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);
    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));
    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));
    // Add a  little list
    createList(subCatPart);/*  w  w w. ja v a  2 s  .  c om*/
    // Add a small table
    createTable(subCatPart);
    // Now a small table
    // Now add all this to the document
    document.add(catPart);
    // Next section
    anchor = new Anchor("Second Chapter", catFont);
    anchor.setName("Second Chapter");
    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);
    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));
    // Now add all this to the document
    document.add(catPart);

}

From source file:FirstPdf.java

private static void createTable(Section subCatPart) throws BadElementException {
    Table t = new Table(3, 2);
    t.setBorderColor(Color.GRAY);
    t.setPadding(4);/*from   w  ww  .j a  va  2s .  c o m*/
    t.setSpacing(4);
    t.setBorderWidth(1);
    Cell c1 = new Cell("Table Header 1");
    c1.setHeader(true);
    t.addCell(c1);
    c1 = new Cell("Table Header 2");
    t.addCell(c1);
    c1 = new Cell("Table Header 3");
    t.addCell(c1);
    t.endHeaders();
    t.addCell("1.0");
    t.addCell("1.1");
    t.addCell("1.2");
    t.addCell("2.1");
    t.addCell("2.2");
    t.addCell("2.3");
    subCatPart.add(t);
}

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);
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private void printNodePdf(Node node, Chapter chapter) throws Exception {
    Section section;
    String id = node.getDisplayId(nodeIdType);
    if (id == null || id.length() == 0)
        id = node.getId().toString();/*  w  w w . j ava 2  s . c  o m*/
    String tmp = "Activity " + id + ": \"" + node.getName().replace('\n', ' ') + "\n";
    Paragraph sTitle = new Paragraph(tmp, sectionFont);
    section = chapter.addSection(sTitle, options.contains(SECTION_NUMBER) ? 2 : 0);
    String summary = node.getAttribute(WorkAttributeConstant.DESCRIPTION);
    if (summary != null && summary.length() > 0) {
        printBoldParagraphsPdf(section, summary);
    }

    if (options.contains(DOCUMENTATION)) {
        String detail = node.getAttribute(WorkAttributeConstant.DOCUMENTATION);
        if (detail != null && detail.length() > 0) {
            printHtmlParagraphsPdf(section, detail, options.contains(SECTION_NUMBER) ? 2 : 0);
            section.add(new Paragraph("\n",
                    FontFactory.getFont(FontFactory.TIMES, 4, Font.NORMAL, new Color(0, 0, 0))));
        }
    }
    if (options.contains(ATTRIBUTES) && !node.getAttributes().isEmpty()) {
        printAttributesPdf(section, node.getAttributes(), options.contains(SECTION_NUMBER) ? 2 : 0);
    }
    section.add(new Paragraph("\n", normalFont));
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private void printBoldParagraphsPdf(Section section, String content) {
    if (content == null || content.length() == 0)
        return;// ww  w. j a  v a  2 s. c  o m
    String[] details = content.split("\n");
    String tmp = null;
    for (int j = 0; j < details.length; j++) {
        if (details[j].length() == 0) {
            if (tmp != null)
                section.add(new Paragraph(tmp + "\n", boldFont));
            tmp = null;
        } else if (tmp == null) {
            tmp = details[j];
        } else {
            tmp += " " + details[j];
        }
    }
    if (tmp != null) {
        section.add(new Paragraph(tmp + "\n", boldFont));
    }
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private void addSectionContentPdf(Section section, Object one, int parent_level) {
    if (one == null)
        return;/*from  w  ww . ja va2  s  .  c o  m*/
    if (one instanceof List<?>) {
        for (Object two : (List<?>) one) {
            addSectionContentPdf(section, two, parent_level);
        }
    } else if (one instanceof TempSectionPdf) {
        section.addSection(((TempSectionPdf) one).title, parent_level == 0 ? 0 : (parent_level + 1));
    } else {
        section.add(one);
    }
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private void printAttributesPdf(Section section, List<AttributeVO> attrs, int parentLevel) {
    Paragraph sTitle = new Paragraph("Activity Attributes", subSectionFont);
    Section subsection = section.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1));
    com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f);
    for (AttributeVO attr : attrs) {
        if (excludeAttribute(attr.getAttributeName(), attr.getAttributeValue()))
            continue;
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(attr.getAttributeName(), fixedWidthFont));
        String v = attr.getAttributeValue();
        if (v == null)
            v = "";
        phrase.add(new Chunk(": " + v, normalFont));
        list.add(new ListItem(phrase));
    }//  w w  w .j  av a  2 s  .  co m
    subsection.add(list);
}

From source file:com.centurylink.mdw.designer.pages.ExportHelper.java

License:Apache License

private void printVariablesPdf(Chapter chapter, List<VariableVO> variables, int parentLevel) {
    Paragraph sTitle = new Paragraph("Process Variables", sectionFont);
    Section section = chapter.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1));
    com.lowagie.text.List list = new com.lowagie.text.List(false, false, 10.0f);
    for (VariableVO var : variables) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(var.getVariableName(), fixedWidthFont));
        String v = var.getVariableType();
        if (var.getDescription() != null)
            v += " (" + var.getDescription() + ")";
        phrase.add(new Chunk(": " + v + "\n", normalFont));
        list.add(new ListItem(phrase));
    }//from w w  w  .j  av  a2 s.co  m
    section.add(list);
}

From source file:com.exam.server.ConvertPDF.java

private static void createTable(Section subCatPart, ArrayList<DeviceDTO> input) throws BadElementException {
    //                PdfPTable table = new PdfPTable(input.size()+1);
    PdfPTable table = new PdfPTable(6);
    System.out.println("size::" + input.size());

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Part2 Id"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);//from   w  ww  . ja v a2s. co m

    c1 = new PdfPCell(new Phrase("Id Company"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Address"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase("Data1"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase("Time1"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase("Time2"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    for (int i = 0; i < input.size(); i++) {
        table.addCell("" + input.get(i).getPart2Id());
        table.addCell("" + input.get(i).getIdCompany());
        table.addCell(input.get(i).getAddress1());
        table.addCell(input.get(i).getData1());
        table.addCell(input.get(i).getTime1());
        table.addCell(input.get(i).getTime2());
    }

    subCatPart.add(table);

}

From source file:com.itext.test.FirstPdf.java

private static void addContent(Document document) throws DocumentException {
    ////from   w  ww  . ja v  a2s. com
    //   Anchor anchor = new Anchor();
    //
    //anchor.setName("First Chapter");
    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    //List
    createList(subCatPart);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // Table
    createTable(subCatPart);

    // document
    document.add(catPart);

    // Next section

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph("a"), 1);

    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // now add all this to the document
    document.add(catPart);

}