Example usage for com.itextpdf.text Section add

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

Introduction

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

Prototype

@Override
public boolean add(final Element element) 

Source Link

Document

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

Usage

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*w  w  w  . j a v a 2 s .  c  o m*/
 * chart 
 *
 * @param section chart   section ?
 * @param e chart   element
 * @throws Exception
 */
public static void setChart(PdfWriter writer, Section section, Element e) throws Exception {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Element e1 : e.getChildren()) {
        if (!e1.getChild("column").getText().equals(FileType.DIRECTORY.toString())
                && !e1.getChild("column").getText().equals(FileType.SUM.toString())) {
            dataset.setValue(Integer.parseInt(e1.getChild("value").getText()), e.getAttributeValue("title"),
                    e1.getChild("column").getText());
        }
    }

    JFreeChart chart = ChartFactory.createBarChart3D(e.getAttributeValue("title"), "", "", dataset,
            PlotOrientation.VERTICAL, false, true, false);

    CategoryPlot plot = chart.getCategoryPlot();
    java.awt.Font labelFont = chart.getCategoryPlot().getDomainAxis().getLabelFont();
    plot.getDomainAxis().setLabelFont(new java.awt.Font(labelFont.getName(), Font.NORMAL, 6));
    plot.getDomainAxis().setTickLabelFont(new java.awt.Font(labelFont.getName(), Font.NORMAL, 6));

    PdfContentByte cb = writer.getDirectContent();
    PdfTemplate bar = cb.createTemplate(500, 150);
    Graphics2D g2d2 = new PdfGraphics2D(bar, 500, 150);
    Rectangle2D r2d2 = new Rectangle2D.Double(0, 0, 500, 150);
    chart.draw(g2d2, r2d2);
    g2d2.dispose();

    Image image = Image.getInstance(bar);
    image.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
    section.add(image);
}

From source file:com.auskeny.ems.print.PdfCreator.java

public 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 list
    createList(subCatPart);//  w  w w.  j  av  a2 s .c om
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // add a table
    createTable(subCatPart);

    // 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:com.bazzar.base.service.impl.CreateInvoicePDF.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 list
    createList(subCatPart);//  www.ja v  a2 s .c o m
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // Add a table
    createTable(subCatPart);

    // 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:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printAttributes(Section section, List<Attribute> attrs, int parentLevel) {
    Paragraph sTitle = new Paragraph("Activity Attributes", subSectionFont);
    Section subsection = section.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1));
    com.itextpdf.text.List list = new com.itextpdf.text.List(false, false, 20.0f);
    for (Attribute attr : attrs) {
        if (excludeAttribute(attr.getAttributeName(), attr.getAttributeValue()))
            continue;
        Phrase phrase = new com.itextpdf.text.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));
    }//from w w  w.  j a va  2  s .  c  o  m
    subsection.add(list);
}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printVariables(Chapter chapter, List<Variable> variables, int parentLevel) {
    Paragraph sTitle = new Paragraph("Process Variables", sectionFont);
    Section section = chapter.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1));
    com.itextpdf.text.List list = new com.itextpdf.text.List(false, false, 10.0f);
    for (Variable var : variables) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(var.getName(), fixedWidthFont));
        String v = var.getType();
        if (var.getDescription() != null)
            v += " (" + var.getDescription() + ")";
        phrase.add(new Chunk(": " + v + "\n", normalFont));
        list.add(new ListItem(phrase));
    }// ww  w. j ava  2 s  .co  m
    section.add(list);
}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printActivity(Activity act, Chapter chapter) throws Exception {
    Section section;
    String tmp = ACTIVITY + act.getLogicalId() + ": \"" + act.getName().replace('\n', ' ') + "\n";
    Paragraph sTitle = new Paragraph(tmp, sectionFont);
    section = chapter.addSection(sTitle, 2);
    String summary = act.getAttribute(WorkAttributeConstant.DESCRIPTION);
    if (summary != null && summary.length() > 0) {
        printBoldParagraphs(section, summary);
    }// ww w. j  a v a2  s  . c  o m

    String detail = act.getAttribute(WorkAttributeConstant.DOCUMENTATION);
    if (detail != null && detail.length() > 0) {
        printHtmlParagraphs(section, detail, 2);
        section.add(new Paragraph("\n", FontFactory.getFont(FontFactory.TIMES, 4, Font.NORMAL)));
    }
    if (!act.getAttributes().isEmpty()) {
        printAttributes(section, act.getAttributes(), 2);
    }
    section.add(new Paragraph("\n", normalFont));
}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printBoldParagraphs(Section section, String content) {
    if (content == null || content.length() == 0)
        return;/*from   www .j av  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.pdf.PdfExportHelper.java

License:Apache License

private void printHtmlParagraphs(Section section, String content, int parentLevel) throws Exception {
    if (content == null || content.length() == 0)
        return;//www  . ja v a 2  s  .  c o  m
    Paragraph comb = new Paragraph();
    ElementList list = XMLWorkerHelper.parseToElementList(content, null);
    for (Element element : list) {
        comb.add(element);
    }
    section.add(comb);
    section.add(new Paragraph("\n", normalFont));
}

From source file:com.debashubham.dumpy.ChainageCalcActivity.java

private void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("Survey Report", catFont);
    anchor.setName("SurveyReport");

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

    Paragraph subPara = new Paragraph("Entries:", subFont);
    Section subCatPart = catPart.addSection(subPara);

    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);/*w  w w  . java 2  s.  co  m*/
    subCatPart.add(paragraph);

    // add a table
    createTable(subCatPart);

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

From source file:com.debashubham.dumpy.ChainageCalcActivity.java

private void createTable(Section subCatPart) throws DocumentException {
    PdfPTable entry_table = new PdfPTable(10);
    entry_table.setWidthPercentage(100);
    //        entry_table.setWidths(new float[]{0.25f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,0.5f,1.0f});
    PdfPCell id = new PdfPCell(new Phrase("Station Point"));
    id.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell left_row = new PdfPCell(new Phrase("CH. Left(m)"));
    left_row.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell center_row = new PdfPCell(new Phrase("CH. Center(m)"));
    center_row.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell right_row = new PdfPCell(new Phrase("CH. Right(m)"));
    right_row.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell bs = new PdfPCell(new Phrase("BS(m)"));
    bs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell is = new PdfPCell(new Phrase("IS(m)"));
    is.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell fs = new PdfPCell(new Phrase("FS(m)"));
    fs.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell hi = new PdfPCell(new Phrase("HI(m)"));
    hi.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell rl = new PdfPCell(new Phrase("RL(m)"));
    rl.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell remarks = new PdfPCell(new Phrase("REMARKS"));
    remarks.setHorizontalAlignment(Element.ALIGN_CENTER);
    entry_table.addCell(id);//  w  w w  .  j  a v  a2 s  .  c  om
    entry_table.addCell(left_row);
    entry_table.addCell(center_row);
    entry_table.addCell(right_row);
    entry_table.addCell(bs);
    entry_table.addCell(is);
    entry_table.addCell(fs);
    entry_table.addCell(hi);
    entry_table.addCell(rl);
    entry_table.addCell(remarks);
    entry_table.setHeaderRows(1);
    int largest = rl_list.size();

    Log.e("Total RL:", String.valueOf(largest));
    double total_bs = 0, total_fs = 0, first_rl = 0, last_rl = 0;

    for (int i = 1; i <= largest; i++) {

        entry_table.addCell(String.valueOf(i));

        if (i == 1)
            first_rl = rl_list.get(i);
        if (i == largest)
            last_rl = rl_list.get(i);

        if (left.containsKey(i)) {
            entry_table.addCell(String.valueOf(left.get(i)));
            entry_table.addCell("");
            entry_table.addCell("");
        } else if (center.containsKey(i)) {
            entry_table.addCell("");
            entry_table.addCell(String.valueOf(center.get(i)));
            entry_table.addCell("");
        } else if (right.containsKey(i)) {
            entry_table.addCell("");
            entry_table.addCell("");
            entry_table.addCell(String.valueOf(right.get(i)));
        } else {
            entry_table.addCell("");
            entry_table.addCell("");
            entry_table.addCell("");
        }

        if (bs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(bs_list.get(i)));
            total_bs += bs_list.get(i);
            Log.e("TABLE:", "BS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "BS not entered");
        }
        if (is_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(is_list.get(i)));
            Log.e("TABLE:", "IS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "IS not entered");
        }
        if (fs_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(fs_list.get(i)));
            total_fs += fs_list.get(i);
            Log.e("TABLE:", "FS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "FS not entered");
        }
        if (hi_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(hi_list.get(i)));
            Log.e("TABLE:", "HI");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "HI not entered");
        }
        if (rl_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(rl_list.get(i)));
            Log.e("TABLE:", "RL");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "RL not entered");
        }
        if (remarks_list.containsKey(i)) {
            entry_table.addCell(String.valueOf(remarks_list.get(i)));
            Log.e("TABLE:", "REMARKS");
        } else {
            entry_table.addCell("");
            Log.e("TABLE:", "REMARKS not entered");
        }
    }
    subCatPart.add(entry_table);
    Log.e("Total BS:", String.valueOf(total_bs));
    Log.e("Total FS:", String.valueOf(total_fs));
    Log.e("First RL:", String.valueOf(first_rl));
    Log.e("Last RL:", String.valueOf(last_rl));
    Paragraph check_para = new Paragraph("Arithmetic Check:", subFont);
    addEmptyLine(check_para, 2);
    check_para.add("Summation(BS) - Summation(FS) = Last RL - First RL");
    addEmptyLine(check_para, 1);
    double bsfs_diff = Math.round((total_bs - total_fs) * 1000.0) / 1000.0;
    double rl_diff = Math.round((last_rl - first_rl) * 1000.0) / 1000.0;
    boolean checktrue = (bsfs_diff) == (rl_diff) ? true : false;
    check_para.add(String.valueOf(bsfs_diff) + " = " + String.valueOf(rl_diff));
    addEmptyLine(check_para, 1);
    if (checktrue) {
        check_para.setSpacingBefore(20);
        check_para.add("OK");
    } else {
        check_para.setSpacingBefore(20);
        check_para.add("Check Fail!");
    }
    addEmptyLine(check_para, 1);
    check_para.add("_______________________________________________________");
    subCatPart.add(check_para);
    Paragraph legend_para = new Paragraph("LEGEND:", subFont);
    addEmptyLine(legend_para, 1);
    legend_para.add("BS : Back Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("IS : Intermediate Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("FS : Fore Sight");
    addEmptyLine(legend_para, 1);
    legend_para.add("HI : Height of Instrument");
    addEmptyLine(legend_para, 1);
    legend_para.add("RL : Reduced Level");
    addEmptyLine(legend_para, 1);
    legend_para.add("CH. : Chainage");
    subCatPart.add(legend_para);
}