Example usage for com.itextpdf.text Paragraph add

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

Introduction

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

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void addTables(Document document, TreeObject rootObject) throws DocumentException {
    // TODO Paul add table of contents/etc.?
    // Table of Contents
    Paragraph paragraph = new Paragraph();
    paragraph.add("Table of Contents\n\n");

    for (TreeObject treeObject : rootObject.getChildObjects()) {
        if (treeObject.isChecked()) {
            addTocSection(paragraph, treeObject, String.valueOf(currentChapter));
            currentChapter++;//from   w ww.j  av  a 2s.  c o  m
        }
    }
    currentChapter = 1;

    document.add(paragraph);

    // Table of Figures
    // Table of Tables
}

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void addTocSection(Paragraph paragraph, TreeObject treeObject, String sectionNumber) {
    int subsectionNumber = 1;

    if (treeObject.isChecked()) {
        StringBuffer sb = new StringBuffer();
        sb.append(sectionNumber);//from   w  ww . ja v  a 2 s  .co  m
        sb.append(". ");
        sb.append(treeObject.getTitle());
        sb.append("\n");
        paragraph.add(sb.toString());
    }

    // TODO Paul Print out the data sections

    // Print out the children
    if ((treeObject.getChildObjects() != null) && (treeObject.getChildObjects().size() > 0)) {
        for (TreeObject childObject : treeObject.getChildObjects()) {
            String currentSection = sectionNumber + "." + String.valueOf(subsectionNumber);
            if (treeObject.isChecked()) {
                addTocSection(paragraph, childObject, currentSection);
                subsectionNumber++;
            }
        }
    }
}

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void populateChapter(TreeObject treeObject, Chapter chapter) throws DocumentException {
    // If there are children, don't display this object's data
    if ((treeObject.getChildObjects() == null) || (treeObject.getChildObjects().size() == 0)) {
        // Create the Data Paragraphs (displayObjects)
        if ((treeObject.getDisplayData() != null)
                && (treeObject.getDisplayData().getDisplayObjects() != null)) {
            for (DisplayObject displayObject : treeObject.getDisplayData().getDisplayObjects()) {
                Paragraph paragraph = new Paragraph(displayObject.getTitle(), sectionTitleFont);

                paragraph.add("\n");
                createDataSection(paragraph, displayObject);

                chapter.addSection(paragraph);
            }//w  w  w. j ava2s.co  m
        }
    }
    // If there are children, display them
    else {
        for (TreeObject childTreeObject : treeObject.getChildObjects()) {
            Paragraph title = new Paragraph(childTreeObject.getTitle(), sectionTitleFont);
            Paragraph content = new Paragraph("\n");

            generateData(content, childTreeObject);

            chapter.addSection(title);
            chapter.add(content);
        }
    }
}

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void generateData(Paragraph paragraph, TreeObject treeObject) {
    // TODO Paul take into consideration TreeObjects that have children (don't display current, make a section for each child)

    for (DisplayObject displayObject : treeObject.getDisplayData().getDisplayObjects()) {
        createDataSection(paragraph, displayObject);
        paragraph.add("\n");
    }//from www  . j  a v a2s .  c  o  m
}

From source file:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

private static void createDataSection(Paragraph paragraph, DisplayObject displayObject) {
    if (displayObject == null || displayObject.getObjects() == null) {
        return;//from w  w  w .  j a v a2s. c  om
    }

    // See if the DisplayObject has a list or a single object
    if (displayObject.getObjects().size() == 1) {
        TreeObject treeObject = displayObject.getObjects().get(0); // There's only 1 item

        // For each column, create/add a label with the title and the data
        int i = 0;
        for (String columnName : displayObject.getColumnNames()) {
            StringBuffer sb = new StringBuffer();

            // Add the column title
            sb.append(displayObject.getColumnTitles()[i]);
            sb.append(": ");

            // Get the value of the field
            try {
                Field field = treeObject.getClass().getDeclaredField(columnName);
                String val = (String) field.get(treeObject);
                if (val == null) {
                    val = "";
                }
                // Add the value
                sb.append(val);
                sb.append("\n");
            } catch (NoSuchFieldException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // Put the string into the paragraph
            paragraph.add(sb.toString());
            i++;
        }
    } else {
        PdfPTable table = new PdfPTable(displayObject.getColumnTitles().length);
        table.setWidthPercentage(100);
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        for (String columnName : displayObject.getColumnTitles()) {
            table.getDefaultCell().setBackgroundColor(BaseColor.CYAN);
            table.addCell(columnName);
            table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);
        }

        for (TreeObject to1 : displayObject.getObjects()) {
            for (String columnName : displayObject.getColumnNames()) {
                try {
                    Field field = to1.getClass().getDeclaredField(columnName);
                    String val = (String) field.get(to1);
                    if (val == null) {
                        val = "";
                    }
                    table.addCell(val);
                } catch (NoSuchFieldException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        table.getDefaultCell().setColspan(displayObject.getColumnTitles().length);
        table.getDefaultCell().setBorder(SWT.NONE);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        // TODO Paul number the tables
        table.addCell("Table: " + displayObject.getTitle());
        paragraph.add(table);
    }
}

From source file:com.alokomkar.aliensonearth.report.AbstractPdfReport.java

public void addEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }//from www. j  a  v a 2s . c  om
}

From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java

License:Apache License

/**
 * //from w  w  w.  j  ava 2s.c om
 *  Paragraph ?.(Navigation  ?  title ) 
 *
 * @param title 
 * @param pageNumber 
 * @param depth 
 * @param x1 document left 
 * @param x2 document right 
 * @return Paragraph
 */
public Paragraph getTocParagraph(String title, int pageNumber, int depth, float x1, float x2) {

    Font tocFont = new Font(bfKorean, 10);
    if (depth == 0)
        tocFont.setStyle(Font.BOLD);

    Paragraph p = new Paragraph();
    p.setSpacingAfter(5);

    Chunk tit = new Chunk(title + " ", tocFont);
    tit.setAction(PdfAction.gotoLocalPage(title, false));

    Chunk point = new Chunk(".", tocFont);

    Chunk number = new Chunk(" " + pageNumber, tocFont);
    number.setAction(PdfAction.gotoLocalPage(title, false));

    p.add(tit);

    float width = x2 - x1 - tit.getWidthPoint() - number.getWidthPoint() - (depth * 12);

    if ((x2 - x1) < tit.getWidthPoint())
        width = x2 - x1 - (tit.getWidthPoint() - (x2 - x1)) - number.getWidthPoint() - (depth * 12) - 65;

    float i = point.getWidthPoint();
    while (i < width) {
        p.add(point);
        i += point.getWidthPoint();
    }

    p.add(number);

    return p;
}

From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java

License:Apache License

public static void setLastPageInfo(Document doc, PdfWriter writer, int cNum) throws Exception {
    Chapter chapter = PDFWriterUtil.getChapter(MessageUtil.getMessage("pdf.message.chapter.confirm.title"),
            cNum);/* ww w  .  jav a2s.c o m*/

    Paragraph preP = new Paragraph();
    preP.add(new Phrase(MessageUtil.getMessage("pdf.message.chapter.confirm.prepared1"),
            PDFWriterUtil.fnNormalBold));
    preP.add(new Phrase("                                                           ",
            new Font(bfKorean, 10, Font.UNDERLINE)));
    preP.setSpacingBefore(15);
    preP.setSpacingAfter(2);
    chapter.add(preP);

    preP = new Paragraph();
    preP.add(new Phrase(MessageUtil.getMessage("pdf.message.chapter.confirm.prepared2"),
            PDFWriterUtil.fnNormal));
    preP.setIndentationLeft(65);
    preP.setSpacingAfter(14);
    chapter.add(preP);

    preP = new Paragraph();
    preP.add(new Phrase(MessageUtil.getMessage("pdf.message.chapter.confirm.approved1"),
            PDFWriterUtil.fnNormalBold));
    preP.add(new Phrase("                                                           ",
            new Font(bfKorean, 10, Font.UNDERLINE)));
    preP.setSpacingBefore(15);
    preP.setSpacingAfter(2);
    chapter.add(preP);

    preP = new Paragraph();
    preP.add(new Phrase(MessageUtil.getMessage("pdf.message.chapter.confirm.approved2"),
            PDFWriterUtil.fnNormal));
    preP.setIndentationLeft(65);
    preP.setSpacingAfter(14);
    chapter.add(preP);

    cNum++;
    doc.add(chapter);

    chapter = PDFWriterUtil.getChapter(MessageUtil.getMessage("pdf.message.chapter.appendices.title"), cNum);
    Section section = PDFWriterUtil.getSection(chapter,
            MessageUtil.getMessage("pdf.message.chapter.appendices.label1"));

    Chunk url = new Chunk(MessageUtil.getMessage("pdf.message.chapter.appendices.text1"), PDFWriterUtil.fnURL);
    url.setAction(new PdfAction(new URL(MessageUtil.getMessage("pdf.message.chapter.appendices.text1"))));

    preP = new Paragraph(url);
    preP.setIndentationLeft(23);
    preP.setSpacingAfter(14);
    section.add(preP);

    section = PDFWriterUtil.getSection(chapter,
            MessageUtil.getMessage("pdf.message.chapter.appendices.label2"));

    doc.add(chapter);
}

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

License:Apache License

/**
 * Chapter  ?/*from  w w  w. j  a v  a  2  s  . co  m*/
 *
 * @param text Chapter title
 * @param chapterNo Chapter Number
 * @return Chapter
 */
public static Chapter getChapter(String text, int chapterNo) {

    Chapter chapter = new Chapter(text, chapterNo);
    String title = chapter.getTitle().getContent();

    Chunk c = new Chunk(text, fnChapter);
    c.setLocalDestination(title);
    Paragraph chapterPh = new Paragraph();
    chapterPh.add(c);
    chapterPh.setSpacingAfter(12);
    chapter.setTitle(chapterPh);
    return chapter;

}

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

License:Apache License

/**
 * /* w  w w  .j  a  va  2 s.co  m*/
 * Section  ?
 *
 * @param chapter section?  chapter ?
 * @param text section title
 * @param sectionNo section Number
 * @return Section
 */
public static Section getSection(Section chapter, String text) {
    Section section = chapter.addSection(text);
    String title = section.getTitle().getContent();

    Chunk c;
    if (section.getDepth() >= 3) {
        c = new Chunk(text, fnSection2);
    } else {
        c = new Chunk(text, fnSection);
    }
    c.setLocalDestination(title);

    Paragraph sectionPh = new Paragraph();
    sectionPh.add(c);
    sectionPh.setSpacingBefore(8);
    sectionPh.setSpacingAfter(3);
    if (section.getDepth() >= 3)
        sectionPh.setIndentationLeft(23);

    section.setTitle(sectionPh);
    return section;
}