Example usage for com.lowagie.text Paragraph add

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

Introduction

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

Prototype

public boolean add(Object o) 

Source Link

Document

Adds an Object to the Paragraph.

Usage

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

License:Open Source License

/**
 * Parses an explanation text which may have HTML tags
 * embedded, and create appropriate Pdf objects (this
 * is somewhat similar to the rendering process of
 * a webbrowser).//  ww  w  .j  a  v a 2 s .c  om
 *
 * @param text The explanation text (of a package, class or member).
 * @return An array of Phrase objects.
 */
public static Element[] createPdfObjects(String text) {
    Element[] result = new Element[0];

    try {
        initializeParser();

        String content = preProcessHtmlContent(text);
        InputStream in = new ByteArrayInputStream(content.getBytes());

        // Parse the HTML document and return the root node
        Node node = parser.parseDOM(in, null);

        // Now build HTML object tree
        HtmlTag bodyTag = HtmlTagFactory.createTag(null, HtmlTag.TAG_BODY);
        HtmlParserWrapper.processTree(bodyTag, node);

        // Now let every HTML tag object convert itself into one or more PDF objects
        Element[] elements = bodyTag.toPdfObjects();

        // Now compress everything into a list of paragraphs
        ArrayList arrayList = new ArrayList(result.length);
        Paragraph currentParagraph = new Paragraph((float) 11.0);

        arrayList.add(currentParagraph);

        for (int i = 0; i < elements.length; i++) {
            if (elements[i] instanceof Paragraph) {
                currentParagraph = (Paragraph) elements[i];
                arrayList.add(elements[i]);

            } else if (elements[i] instanceof PdfPTable) {
                arrayList.add(elements[i]);
                currentParagraph = new Paragraph((float) 11.0);
                arrayList.add(currentParagraph);

            } else if (elements[i] instanceof List) {
                arrayList.add(elements[i]);
                currentParagraph = new Paragraph((float) 11.0);
                arrayList.add(currentParagraph);
            } else
                currentParagraph.add(elements[i]);
        }

        Object[] obj = arrayList.toArray();
        result = new Element[obj.length];

        for (int i = 0; i < obj.length; i++) {
            result[i] = (Element) obj[i];
        }

    } catch (Exception e) {
        log.error("HTML parsing failed with exception: (package, class, method, member): "
                + State.currentPackage + ", " + State.currentClass + ", " + State.currentMethod + ", "
                + State.currentMember + " : " + text, e);
    }

    return result;
}

From source file:org.areasy.common.doclet.utilities.PDFUtility.java

License:Open Source License

/**
 * Create a cell element./*ww w. j ava  2 s . c  om*/
 */
public static PdfPCell createElementCell(int padding, int alignment, Element[] elements) {
    Element mainElement;

    // If there are no nested tables in content
    if (!hasTablesOrLists(elements)) {
        Paragraph para = new Paragraph();
        para.setAlignment(alignment);

        for (int i = 0; i < elements.length; i++) {
            try {
                para.add(elements[i]);
            } catch (Exception e) {
                String msg = "Failed to add element to paragraph: " + e.toString();
                DocletUtility.error(msg);
            }
        }

        mainElement = para;

    } else {

        PdfPTable cellTable = new PdfPTable(1);
        Paragraph currInnerPara = null;

        for (int i = 0; i < elements.length; i++) {

            Element element = elements[i];

            /* Check for special element created by TagTABLE */
            if (element instanceof TableParagraph)
                element = ((TableParagraph) elements[i]).getTable();

            if (element instanceof PdfPTable || element instanceof List) {

                if (currInnerPara != null) {
                    PdfPCell innerCell = createElementCell(0, alignment, currInnerPara);
                    innerCell.setUseDescender(true); // needs newer iText
                    innerCell.setUseAscender(true); // needs newer iText
                    innerCell.setPaddingBottom(2.0f);
                    cellTable.addCell(innerCell);
                }

                currInnerPara = null;
                cellTable.addCell(createElementCell(0, alignment, element));

            } else {
                if (currInnerPara == null) {
                    currInnerPara = new Paragraph();
                    currInnerPara.setAlignment(alignment);
                }

                try {
                    currInnerPara.add(element);
                } catch (Exception e) {
                    String msg = "Failed to add element to inner paragraph: " + e.toString();
                    DocletUtility.error(msg);
                }
            }
        }

        if (currInnerPara != null)
            cellTable.addCell(createElementCell(0, alignment, currInnerPara));

        mainElement = cellTable;
    }

    return createElementCell(padding, alignment, mainElement);
}

From source file:org.bambrikii.photobank.web.documents.paymentcertificates.impl.PaymentCertificateBuilderRU.java

public void build(OutputStream outputStream) throws DocumentGenerationException {
    Document doc = new Document(PageSize.A4);
    PdfWriter writer;//from ww  w .j  av  a  2 s  . c o  m
    BaseFont baseFont = null;
    try {
        writer = PdfWriter.getInstance(doc, outputStream);

        writer.setEncryption(null, "qweasdzxc".getBytes(), PdfWriter.ALLOW_PRINTING,
                PdfWriter.ENCRYPTION_AES_128);

        doc.open();

        String baseFontPath = getResourcesPath() + "org/bambrikii/photobank/web/documents/ARIAL.TTF";
        final String stampImagePath = getResourcesPath()
                + "org/bambrikii/photobank/web/documents/paymentcertificates/PersonaStarsStamp.png";
        baseFont = BaseFont.createFont(baseFontPath, "Cp1251", true);

        Font baseTextStyle = new com.lowagie.text.Font(baseFont, 10, com.lowagie.text.Font.NORMAL,
                new Color(0, 0, 0));
        Font baseBoldTextStyle = new com.lowagie.text.Font(baseFont, 10, com.lowagie.text.Font.BOLD,
                new Color(0, 0, 0));

        Calendar cal = Calendar.getInstance(getLocale());
        cal.setTime(getData().getDate());

        // Act number
        String actNumber = MessageFormat.format(
                "\u0410\u043a\u0442 \u2116 {0} \u043e\u0442 \u00ab{1}\u00bb {2} {3} \u0433\u043e\u0434\u0430",
                String.valueOf(getData().getNumber()), cal.get(Calendar.DAY_OF_MONTH),
                monthsGenitiveCase.get(cal.get(Calendar.MONTH)).toLowerCase(),
                String.valueOf(cal.get(Calendar.YEAR)));
        Paragraph actNumberParagraph = new Paragraph(actNumber,
                new com.lowagie.text.Font(baseFont, 12, com.lowagie.text.Font.BOLD, new Color(0, 0, 0)));
        actNumberParagraph.setSpacingAfter(19);

        Paragraph cityParagraph = new Paragraph("\u0433. \u041c\u043e\u0441\u043a\u0432\u0430", baseTextStyle);
        cityParagraph.setSpacingAfter(15);

        // Licensor
        Paragraph licensorParagraph = new Paragraph();
        licensorParagraph
                .add(new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0440: ", baseBoldTextStyle));
        licensorParagraph.add(new Chunk(MessageFormat.format("{0}",
                "\u0418\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c \u041b\u0438\u043f\u0430\u0442\u043d\u0438\u043a\u043e\u0432 \u0415\u0432\u0433\u0435\u043d\u0438\u0439 \u0410\u0440\u043a\u0430\u0434\u044c\u0435\u0432\u0438\u0447, \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0421\u0432\u0438\u0434\u0435\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 \u041e\u0413\u0420\u041d \u2116 305501025600011 \u043e\u0442 13.09.2005\u0433."),
                baseTextStyle));
        licensorParagraph.setSpacingAfter(15);

        // Licensee
        Paragraph licenseeParagraph = new Paragraph();
        licenseeParagraph
                .add(new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442: ", baseBoldTextStyle));
        licenseeParagraph.add(new Chunk(getData().getLicensee(), baseTextStyle));
        licenseeParagraph.setSpacingAfter(15);

        // Pre text
        Paragraph pretextParagraph = new Paragraph();
        pretextParagraph.add(new Chunk(
                "\u0412 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0414\u043e\u0433\u043e\u0432\u043e\u0440\u043e\u043c \u041e\u0444\u0435\u0440\u0442\u044b \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u043b \u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0446\u0438\u0444\u0440\u043e\u0432\u044b\u0435 \u043a\u043e\u043f\u0438\u0438) \u0438 \u043d\u0435\u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 (\u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f): ",
                baseTextStyle));
        pretextParagraph.setSpacingAfter(15);

        int defaultLeading = 9;
        // Files table
        Table filesTbl = new Table(5);
        filesTbl.setWidths(new int[] { 5, 35, 35, 10, 15 });
        filesTbl.setBorder(Table.RECTANGLE);
        filesTbl.setBorderWidth(1);
        filesTbl.setSpacing(0);
        filesTbl.setPadding(2);
        filesTbl.setCellsFitPage(false);
        filesTbl.setUseVariableBorders(true);
        filesTbl.setAlignment(Element.ALIGN_LEFT);
        filesTbl.setWidth(100);

        Cell cellheader1 = new Cell(new Phrase(new Chunk("\u2116", baseBoldTextStyle)));
        cellheader1.setHeader(true);
        cellheader1.setLeading(defaultLeading);
        cellheader1.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader1);

        Cell cellheader2 = new Cell(new Phrase(
                new Chunk("\u041d\u043e\u043c\u0435\u0440 \u0444\u043e\u0442\u043e", baseBoldTextStyle)));
        cellheader2.setHeader(true);
        cellheader2.setLeading(defaultLeading);
        cellheader2.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader2);

        Cell cellheader3 = new Cell(
                new Phrase(new Chunk("\u041f\u0435\u0440\u0441\u043e\u043d\u0430", baseBoldTextStyle)));
        cellheader3.setHeader(true);
        cellheader3.setLeading(defaultLeading);
        cellheader3.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader3);

        Cell cellheader4 = new Cell(
                new Phrase(new Chunk("\u0420\u0430\u0437\u043c\u0435\u0440", baseBoldTextStyle)));
        cellheader4.setHeader(true);
        cellheader4.setLeading(defaultLeading);
        cellheader4.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader4);

        Cell cellheader5 = new Cell(
                new Phrase(new Chunk("\u0426\u0435\u043d\u0430 \u0440\u0443\u0431.", baseBoldTextStyle)));
        cellheader5.setHeader(true);
        cellheader5.setLeading(defaultLeading);
        cellheader5.setHorizontalAlignment(Cell.ALIGN_CENTER);
        filesTbl.addCell(cellheader5);
        filesTbl.endHeaders();

        Integer i = 0;
        for (PaymentCertificateDataItem item : getData().getItems()) {
            i++;
            Cell cell1 = new Cell(new Phrase(new Chunk(Integer.toString(i), baseTextStyle)));
            cell1.setLeading(defaultLeading);
            cell1.setHorizontalAlignment(Cell.ALIGN_CENTER);
            cell1.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell1);

            Cell cell2 = new Cell(new Phrase(new Chunk(item.getFilename(), baseTextStyle)));
            cell2.setLeading(defaultLeading);
            cell2.setHorizontalAlignment(Cell.ALIGN_LEFT);
            cell2.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell2);

            Cell cell3 = new Cell(new Phrase(new Chunk(item.getName(), baseTextStyle)));
            cell3.setLeading(defaultLeading);
            cell3.setHorizontalAlignment(Cell.ALIGN_LEFT);
            cell3.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell3);

            Cell cell4 = new Cell(new Phrase(new Chunk(item.getSizeName(), baseTextStyle)));
            cell4.setLeading(defaultLeading);
            cell4.setHorizontalAlignment(Cell.ALIGN_CENTER);
            cell4.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell4);

            Cell cell5 = new Cell(new Phrase(new Chunk(Double.toString(item.getPrice()), baseTextStyle)));
            cell5.setLeading(defaultLeading);
            cell5.setHorizontalAlignment(Cell.ALIGN_CENTER);
            cell5.setBorder(Cell.NO_BORDER);
            filesTbl.addCell(cell5);
        }
        filesTbl.complete();

        // filesTbl.normalize();

        String totalPrice = MessageFormat.format("{0} {1}", String.valueOf(getData().getTotal()),
                getData().getCurrency());

        Paragraph totalParagraph = new Paragraph();
        totalParagraph.setAlignment(Paragraph.ALIGN_RIGHT);

        totalParagraph.add(new Chunk("\u0418\u0442\u043e\u0433\u043e: ", baseTextStyle));
        totalParagraph.add(new Chunk(totalPrice, baseBoldTextStyle));
        totalParagraph.setSpacingAfter(25);

        Paragraph posttext1Paragraph = new Paragraph();
        posttext1Paragraph.add(new Chunk(
                "\u0412\u043e\u0437\u043d\u0430\u0433\u0440\u0430\u0436\u0434\u0435\u043d\u0438\u0435 \u0437\u0430 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442: ",
                baseTextStyle));
        posttext1Paragraph.add(new Chunk(totalPrice, baseBoldTextStyle));
        // posttext1Paragraph.setSpacingAfter(15);

        Paragraph posttext2Paragraph = new Paragraph(
                "\u041d\u0414\u0421 \u043d\u0435 \u043e\u0431\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043f\u0443\u043d\u043a\u0442\u0430\u043c\u0438 2, 3 \u0438 5 \u0441\u0442\u0430\u0442\u044c\u0438 346.11 \u041d\u0430\u043b\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0435\u043a\u0441\u0430 \u0420\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u0439 \u0424\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u0438.",
                baseTextStyle);
        posttext2Paragraph.setSpacingAfter(15);

        Paragraph posttext3Paragraph = new Paragraph(
                "\u041f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0440\u043e\u043a\u043e\u043c \u043d\u0430 1 (\u043e\u0434\u0438\u043d) \u0433\u043e\u0434 \u0441 \u0434\u0430\u0442\u044b \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432 \u0410\u043a\u0442\u0435.",
                baseTextStyle);
        posttext3Paragraph.setSpacingAfter(15);

        Paragraph posttext4Paragraph = new Paragraph();
        posttext4Paragraph.add(new Chunk(
                "\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442 \u043d\u0435 \u0432\u043f\u0440\u0430\u0432\u0435 ",
                baseTextStyle));
        posttext4Paragraph.add(new Chunk("(\u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442\u0441\u044f)",
                baseBoldTextStyle));
        posttext4Paragraph.add(new Chunk(
                ": \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0442\u044c \u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u043a\u043e\u043f\u0438\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438; \u043f\u0440\u043e\u0434\u0430\u0432\u0430\u0442\u044c, \u0441\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u043a\u0430\u0442, \u0430\u0440\u0435\u043d\u0434\u0443, \u043b\u0438\u0437\u0438\u043d\u0433, \u043a\u0430\u043a \u0441\u0430\u043c\u0438 \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0438 \u0444\u0430\u0439\u043b\u044b \u0441 \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u0435\u0439, \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u043a\u0430\u0440\u0442\u043e\u0447\u0435\u043a \u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043a, \u043f\u043e\u0441\u0442\u0435\u0440\u043e\u0432 \u0438 \u043e\u0431\u0440\u0430\u043c\u043b\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u043f\u0440\u043e\u0434\u0443\u043a\u0446\u0438\u0439 \u0432 \u0446\u0435\u043b\u044f\u0445 \u043f\u0440\u043e\u0434\u0430\u0436\u0438; \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0444\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u0442\u044c \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u043c \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0442\u0440\u0435\u0442\u044c\u0438\u043c\u0438 \u043b\u0438\u0446\u0430\u043c\u0438, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c, \u0434\u0435\u043b\u0430\u044f \u0438\u0445 \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438.",
                baseTextStyle));
        posttext4Paragraph.setSpacingAfter(15);

        Paragraph posttext5Paragraph = new Paragraph(
                "\u0421\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u0443\u0441\u043b\u0443\u0433\u0438 \u043f\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u043f\u0440\u0430\u0432 \u043d\u0430 \u0424\u043e\u0442\u043e\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u0432 \u043f\u043e\u043b\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u043c\u0435. \u0421\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u0440\u0435\u0442\u0435\u043d\u0437\u0438\u0439 \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442.",
                baseTextStyle);
        posttext5Paragraph.setSpacingAfter(15);

        // Signatures
        Table signaturesTable = new Table(4);
        signaturesTable.setWidths(new int[] { 10, 40, 10, 40 });
        signaturesTable.setWidth(100);
        signaturesTable.setSpacing(0);
        signaturesTable.setPadding(5);
        signaturesTable.setBorder(Table.NO_BORDER);

        Cell licensorSignature1Cell = new Cell(new Phrase(
                new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0440:", baseBoldTextStyle)));
        licensorSignature1Cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
        licensorSignature1Cell.setBorder(Cell.NO_BORDER);

        Cell licensorSignature2Cell = new Cell(new Phrase(new Chunk(
                "______________/ \u041b\u0438\u043f\u0430\u0442\u043d\u0438\u043a\u043e\u0432 \u0415.\u0410. /",
                baseTextStyle)));
        licensorSignature2Cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
        licensorSignature2Cell.setBorder(Cell.NO_BORDER);
        licensorSignature2Cell.addElement(new Paragraph("\n\n\n\n"));
        licensorSignature2Cell.add(
                // Stamp
                Image.getInstance(stampImagePath));

        Cell licenseeSignature1Cell = new Cell(new Phrase(
                new Chunk("\u041b\u0438\u0446\u0435\u043d\u0437\u0438\u0430\u0442:", baseBoldTextStyle)));
        licenseeSignature1Cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
        licenseeSignature1Cell.setBorder(Cell.NO_BORDER);

        Cell licenseeSignature2Cell = new Cell(new Phrase(new Chunk(
                MessageFormat.format("______________/ {0} /", getData().getLicensee()), baseTextStyle)));
        licenseeSignature2Cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
        licenseeSignature2Cell.setBorder(Cell.NO_BORDER);

        signaturesTable.addCell(new Cell() {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(licensorSignature1Cell);
        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(licenseeSignature1Cell);
        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(licensorSignature2Cell);
        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(licenseeSignature2Cell);

        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });
        signaturesTable.addCell(new Cell(true) {
            {
                setBorder(Cell.NO_BORDER);
            }
        });

        signaturesTable.complete();
        // PdfPTable signaturePdPfTable = signaturesTable.createPdfPTable();

        // Document items
        doc.add(actNumberParagraph);
        doc.add(cityParagraph);
        doc.add(licensorParagraph);
        doc.add(licenseeParagraph);
        doc.add(pretextParagraph);
        doc.add(filesTbl);
        doc.add(totalParagraph);
        doc.add(posttext1Paragraph);
        doc.add(posttext2Paragraph);
        doc.add(posttext3Paragraph);
        doc.add(posttext4Paragraph);
        doc.add(posttext5Paragraph);
        doc.add(signaturesTable);

        doc.close();
    } catch (DocumentException ex) {
        throw new DocumentGenerationException("Exception creating document.", ex);
    } catch (IOException ex) {
        throw new DocumentGenerationException(
                "Exception creating document, required font file may not be found.", ex);
    }
}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java

License:Open Source License

/**
 * This method is used for add the main information table of project summary
 *//*  w w  w .ja v  a  2 s  . c o m*/
private void addMainInformationTable() {

    String startDate, endDate;
    if (project.getStartDate() != null) {
        startDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getStartDate());
    } else {
        startDate = this.messageReturn(null);
    }

    if (project.getEndDate() != null) {
        endDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getEndDate());
    } else {
        endDate = this.messageReturn(null);
    }

    Paragraph cellContent;

    // Add content
    try {
        PdfPTable table = new PdfPTable(4);

        // Set table widths
        table.setLockedWidth(true);
        table.setTotalWidth(480);
        table.setWidths(new int[] { 3, 5, 3, 5 });

        // First row
        cellContent = new Paragraph(this.getText("summaries.project.startDate") + "\n" + " (dd-MM-yyyy)",
                TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);

        cellContent = new Paragraph(this.messageReturn(startDate), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        cellContent = new Paragraph(this.getText("summaries.project.endDate") + "\n" + " (dd-MM-yyyy)",
                TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);

        cellContent = new Paragraph(this.messageReturn(endDate), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        // Second row
        cellContent = new Paragraph(this.getText("summaries.project.managementLiaison"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

        cellContent = new Paragraph(this.messageReturn(project.getLiaisonInstitution().getAcronym() + " - "
                + project.getLiaisonInstitution().getName()), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        cellContent = new Paragraph(this.getText("summaries.project.contactPerson"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

        cellContent = new Paragraph(this.messageReturn(project.getOwner().getComposedName()), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        // Third row
        cellContent = new Paragraph(this.getText("summaries.project.leadOrganization"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);
        if (project.getLeader() == null || project.getLeader().getInstitution() == null) {
            cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
        } else {
            cellContent = new Paragraph(
                    this.messageReturn(
                            this.messageReturn(project.getLeader().getInstitution().getComposedName())),
                    TABLE_BODY_FONT);

        }
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        cellContent = new Paragraph(this.getText("summaries.project.projectLeader"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);
        if (project.getLeaderPerson() == null || project.getLeaderPerson().getUser() == null) {
            cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
        } else {
            cellContent = new Paragraph(
                    this.messageReturn(project.getLeaderPerson().getUser().getComposedName()), TABLE_BODY_FONT);
        }

        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        // Fourth row
        cellContent = (new Paragraph(this.getText("summaries.project.projectType"), TABLE_BODY_BOLD_FONT));
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

        cellContent = new Paragraph(this.messageReturn(project.getType().replaceAll("_", " ")),
                TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        // Fiveth row
        Chunk imdb = null;
        Font hyperLink = new Font(FontFactory.getFont("openSans", 10, Color.BLUE));
        hyperLink.setStyle(Font.UNDERLINE);

        // -- Not Bilateral
        if (!project.isBilateralProject()) {
            cellContent = (new Paragraph(this.getText("summaries.project.detailed"), TABLE_BODY_BOLD_FONT));
            this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

            if (project.getWorkplanName() != null && !project.getWorkplanName().equals("")) {
                imdb = new Chunk(project.getWorkplanName(), hyperLink);
                try {
                    imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL()))));
                } catch (MalformedURLException exp) {
                    imdb = new Chunk(project.getWorkplanName(), TABLE_BODY_FONT);
                    LOG.error("There is an Malformed exception in " + project.getWorkplanName());
                }
            } else {
                imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
            }
        }

        // -- Bilateral
        else {
            cellContent = (new Paragraph(this.getText("summaries.project.ipContributions.proposal.space"),
                    TABLE_BODY_BOLD_FONT));
            this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

            if (project.getBilateralContractProposalName() != null
                    && !project.getBilateralContractProposalName().equals("")) {
                imdb = new Chunk(project.getBilateralContractProposalName(), hyperLink);
                try {
                    imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL()))));
                } catch (MalformedURLException exp) {
                    imdb = new Chunk(project.getBilateralContractProposalName(), TABLE_BODY_FONT);
                    LOG.error("There is an Malformed exception in bilateral contract: "
                            + project.getBilateralContractProposalName());
                }
            } else {
                imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
            }
        }

        cellContent = new Paragraph();
        cellContent.add(imdb);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        document.add(table);
        document.add(Chunk.NEWLINE);
    } catch (DocumentException e) {
        LOG.error(
                "-- generatePdf() > There was an error adding the table with content for case study summary. ",
                e);
    }
}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java

License:Open Source License

/**
 * This method is used for add Outcomes in the project summary
 *//*from   ww w .ja v  a  2 s.com*/
private void addProjectOutcomes(String number) {
    try {
        Paragraph outcomesBlock = new Paragraph();
        outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED);
        Paragraph title = new Paragraph(number + ". " + this.getText("summaries.project.outcome"),
                HEADING2_FONT);
        outcomesBlock.add(title);
        outcomesBlock.add(Chunk.NEWLINE);
        ;
        title = new Paragraph();
        title.setFont(HEADING3_FONT);
        title.add(number + ".1 " + this.getText("summaries.project.outcomeNarrative"));
        outcomesBlock.add(title);
        outcomesBlock.add(Chunk.NEWLINE);
        ;

        // Project outcome statement
        Paragraph body = new Paragraph();
        body.setFont(BODY_TEXT_BOLD_FONT);
        body.add(this.getText("summaries.project.outcomeStatement"));

        // body.setFont(BODY_TEXT_FONT);
        if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(midOutcomeYear)) == null
                || project.getOutcomes().get(String.valueOf(midOutcomeYear)).getStatement() == null
                || project.getOutcomes().get(String.valueOf(midOutcomeYear)).getStatement().equals("")) {
            body.add(": ");
            body.setFont(BODY_TEXT_FONT);
            body.add(this.getText("summaries.project.empty"));
        } else {
            body.setFont(BODY_TEXT_FONT);
            body.add(Chunk.NEWLINE);
            body.add(this
                    .messageReturn(project.getOutcomes().get(String.valueOf(midOutcomeYear)).getStatement()));

        }
        body.add(Chunk.NEWLINE);
        ;
        outcomesBlock.add(body);

        try {
            document.newPage();
            // document.add(outcomesBlock);
        } catch (Exception e) {
            LOG.error("There was an error trying to add the project focuses to the project summary pdf", e);
        }

        Anchor anchor;

        ////////////////// Reporting
        PdfPTable table;

        // **********************************************************************************
        // *************************** Outcome Case Studies *************************************
        // **********************************************************************************

        if (project.isReporting()) {
            document.newPage();
            Paragraph cell;

            if (project.getCaseStudies().isEmpty()) {
                document.add(
                        new Paragraph(this.getText("summaries.project.reporting.outcome.not.case.studies")));
            } else {
                title = new Paragraph();
                title.add(Chunk.NEWLINE);
                // document.add(title);
            }
            List<Project> lst = projectManager.getAllProjectsBasicInfo(APConstants.REPORTING_SECTION);
            Collections.sort(lst, new Comparator<Project>() {

                @Override
                public int compare(Project s1, Project s2) {
                    Integer p1 = s1.getId();
                    Integer p2 = s2.getId();
                    return p1.compareTo(p2);
                }
            });
            for (Project project : lst) {
                project = projectManager.getProject(project.getId());
                if (project.isWorkplanRequired()) {
                    String workPlanURL = this.getWorkplanURL();
                    if (workPlanURL != null || project.getWorkplanName() != null) {
                        project.setWorkplanURL(workPlanURL + project.getWorkplanName());
                    }
                }
                // Get a route for the bilateral contract
                if (project.isBilateralProject()) {
                    String bilateralContractURL = this.getBilateralContractURL();
                    if (bilateralContractURL != null || project.getBilateralContractProposalName() != null) {
                        project.setWorkplanURL(
                                bilateralContractURL + project.getBilateralContractProposalName());
                    }
                }

                // Getting the information of the Regions program
                project.setRegions(
                        ipProgramManager.getProjectFocuses(project.getId(), APConstants.REGION_PROGRAM_TYPE));

                // Getting the information of the Flagships program
                project.setFlagships(
                        ipProgramManager.getProjectFocuses(project.getId(), APConstants.FLAGSHIP_PROGRAM_TYPE));

                List<ProjectPartner> projectPartnerList = this.partnerManager.getProjectPartners(project, 0);

                for (ProjectPartner projectPartner : projectPartnerList) {
                    projectPartner
                            .setPartnerPersons(this.partnerPersonManager.getPartnerPersons(projectPartner));
                    projectPartner.setPartnerContributors(
                            partnerManager.getProjectPartnerContributors(projectPartner));
                }
                project.setProjectPartners(projectPartnerList);
                this.project = project;

                List<CasesStudies> caseStudiesList = caseStudiesManager.getCaseStudysByProject(project.getId());

                List<IPIndicator> ipIndicatorList;
                IPIndicator ipIndicator;
                if (caseStudiesList != null) {
                    if (!caseStudiesList.isEmpty()) {
                        try {
                            this.addProjectTitle();
                            this.addMainInformationTable();
                        } catch (Exception e) {
                            System.out.println(project.getId());
                            e.printStackTrace();
                        }
                    }

                    for (CasesStudies caseStudie : caseStudiesList) {
                        ipIndicatorList = new ArrayList<IPIndicator>();
                        for (CaseStudieIndicators indicatorCaseStudie : caseStudie
                                .getCaseStudieIndicatorses()) {
                            ipIndicator = indicatorManager
                                    .getIndicatorFlgship(indicatorCaseStudie.getIdIndicator());
                            ipIndicatorList.add(ipIndicator);
                        }
                        caseStudie.setCaseStudyIndicators(ipIndicatorList);
                    }
                    project.setCaseStudies(caseStudiesList);

                    int counter = 0;
                    for (CasesStudies caseStudy : project.getCaseStudies()) {

                        counter++;
                        table = new PdfPTable(1);
                        table.setLockedWidth(true);
                        table.setTotalWidth(500);

                        // case study
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.case.study") + " #" + counter,
                                TABLE_HEADER_FONT);
                        this.addTableHeaderCell(table, cell);
                        // this.addCustomTableCell(table, cell, Element.ALIGN_LEFT, BODY_TEXT_FONT, Color.WHITE,
                        // table.getNumberOfColumns(), 0, false);

                        // Title
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.title"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getTitle());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // Outcome statement
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.outcomestatement"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getOutcomeStatement());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // Research outputs
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.researchoutputs"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getResearchOutputs());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // Research partners
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.researchPartners"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getResearchPartners());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // activities Contributed
                        cell = new Paragraph(
                                this.getText(
                                        "summaries.project.reporting.outcome.casestudy.activitiesContributed"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getActivities());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // Non Research Partners
                        cell = new Paragraph(
                                this.getText(
                                        "summaries.project.reporting.outcome.casestudy.nonResearchPartners"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getNonResearchPartneres());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // Output Users
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.outputUsers"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getOutputUsers());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // Output Used
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.outputWasUsed"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getOutputUsed());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // Evidence
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.evidenceOutcome"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getEvidenceOutcome());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // References
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.references"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getReferencesCase());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // Outcome indicators
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.primaryOutcome",
                                        new String[] { String.valueOf(this.midOutcomeYear) }),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add("\n");
                        for (IPIndicator _ipIndicator : caseStudy.getCaseStudyIndicators()) {
                            if (_ipIndicator.getOutcome() != null) {
                                cell.add(_ipIndicator.getOutcome().getDescription());
                            }
                            cell.add(" " + _ipIndicator.getDescription() + "\n");
                        }
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // Explain link
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.explainLink"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(caseStudy.getExplainIndicatorRelation());
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // year
                        cell = new Paragraph(this.getText("summaries.project.reporting.outcome.casestudy.year"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        cell.add(String.valueOf(caseStudy.getYear()));
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        // upload
                        cell = new Paragraph(
                                this.getText("summaries.project.reporting.outcome.casestudy.upload"),
                                TABLE_BODY_BOLD_FONT);
                        cell.setFont(TABLE_BODY_FONT);
                        if (caseStudy.getFile() == null || caseStudy.getFile().equals("")) {
                            cell.add(this.messageReturn(null));
                        } else {
                            anchor = new Anchor(caseStudy.getFile(), TABLE_BODY_FONT_LINK);
                            anchor.setReference(config.getDownloadURL() + "/projects/" + project.getId()
                                    + "/caseStudy/" + caseStudy.getFile());
                            cell.add(anchor);
                        }
                        this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                        document.add(table);
                        document.add(new Paragraph(Chunk.NEWLINE));

                    }
                }

                document.newPage();
            }
        }

    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java

License:Open Source License

/**
 * Entering the project title in the summary
 *//*from  w  ww .j  a  v a 2 s  .  c  o m*/
private void addProjectTitle() {
    LineSeparator line = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -7);
    Paragraph paragraph = new Paragraph();
    line.setLineColor(titleColor);
    try {
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        paragraph.setFont(BODY_TEXT_BOLD_FONT);
        paragraph.add("Project: ");
        paragraph.setFont(BODY_TEXT_FONT);
        paragraph.add(this.messageReturn("P" + project.getId() + " - "));
        paragraph.add(this.messageReturn(project.getTitle()));
        paragraph.add(line);
        document.add(paragraph);
        document.add(Chunk.NEWLINE);
        ;
    } catch (DocumentException e) {
        LOG.error("There was an error trying to add the project title to the project summary pdf", e);
    }
}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

/**
 * This method add Activities for the summary project
 *///from   ww  w  . jav  a  2  s.c o  m
private void addActivities() {

    try {
        document.newPage();
        Paragraph activityBlock = new Paragraph("6. " + this.getText("summaries.project.activity"),
                HEADING2_FONT);
        activityBlock.setAlignment(Element.ALIGN_JUSTIFIED);
        activityBlock.add(Chunk.NEWLINE);

        PdfPTable table;
        List<Activity> listActivities = project.getActivities();

        if (listActivities.isEmpty()) {
            activityBlock.setFont(BODY_TEXT_FONT);
            activityBlock.add(this.getText("summaries.project.empty"));
            document.add(activityBlock);
        } else {
            activityBlock.add(Chunk.NEWLINE);
            document.add(activityBlock);
            int counter = 1;
            for (Activity activity : listActivities) {
                boolean printActity = true;
                if (activity != null) {
                    if (!project.isReporting()) {
                        Calendar c = Calendar.getInstance();
                        c.setTime(activity.getEndDate());
                        Calendar cStartDate = Calendar.getInstance();
                        cStartDate.setTime(activity.getStartDate());
                        if (c.get(Calendar.YEAR) != config.getPlanningCurrentYear()) {
                            if (cStartDate.get(Calendar.YEAR) != config.getPlanningCurrentYear()) {
                                printActity = false;
                            }

                        }

                        if (activity.getActivityStatus() == Integer
                                .parseInt(ProjectStatusEnum.Cancelled.getStatusId())) {
                            printActity = false;
                        }
                    }
                    if (printActity) {
                        table = new PdfPTable(2);
                        table.setTotalWidth(480);
                        table.setLockedWidth(true);

                        // Header table
                        activityBlock = new Paragraph();
                        activityBlock.setAlignment(Element.ALIGN_CENTER);
                        activityBlock.setFont(TABLE_HEADER_FONT);
                        activityBlock.add("Activity #" + counter);

                        PdfPCell cell_new = new PdfPCell(activityBlock);
                        cell_new.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE);
                        cell_new.setBackgroundColor(TABLE_HEADER_BACKGROUND);
                        cell_new.setUseBorderPadding(true);
                        cell_new.setPadding(3);
                        cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR);
                        cell_new.setColspan(2);

                        this.addTableHeaderCell(table, cell_new);

                        // Activity title
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.title"));

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(this.messageReturn(activity.getTitle()));
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                        // Activity description
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.description"));

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(this.messageReturn(activity.getDescription()));
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                        String startDate = null;
                        String endDate = null;
                        try {
                            startDate = new SimpleDateFormat("dd-MM-yyyy").format(activity.getStartDate());
                        } catch (Exception e) {

                        }
                        try {

                            endDate = new SimpleDateFormat("dd-MM-yyyy").format(activity.getEndDate());
                        } catch (Exception e) {

                        }

                        // Activity Start Date
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.startDate") + " (dd-MM-yyyy)" + ": ");

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(startDate);
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);

                        // Activity End Date
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.endDate") + " (dd-MM-yyyy)" + ": ");

                        activityBlock.setFont(TABLE_BODY_FONT);
                        activityBlock.add(endDate);
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);

                        // Activity Leader
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.activityLeader") + ": ");
                        activityBlock.setFont(TABLE_BODY_FONT);

                        PartnerPerson activityPartnerPerson = activity.getLeader();

                        if (activityPartnerPerson != null) {
                            activityBlock.add(activityPartnerPerson.getComposedName());
                            String partnerInstitution = this.mapPartnerPersons
                                    .get(String.valueOf(activityPartnerPerson.getId()));
                            if (partnerInstitution != null) {
                                activityBlock.add(", " + partnerInstitution);
                            }
                        } else {
                            activityBlock.add(this.getText("summaries.project.empty"));
                        }
                        activityBlock.add(Chunk.NEWLINE);
                        this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                        // if (project.isReporting()) {
                        // status
                        activityBlock = new Paragraph();
                        activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                        activityBlock.add(this.getText("summaries.project.activities.status"));

                        activityBlock.setFont(TABLE_BODY_FONT);
                        if (activity.getActivityStatus() > 0) {
                            activityBlock.add(statuses.get(String.valueOf(activity.getActivityStatus())));
                        } else {
                            activityBlock.add(" " + this.getText("summaries.project.empty"));
                            // }
                            activityBlock.add(Chunk.NEWLINE);

                            if (activity.isStatusCancelled() || activity.isStatusExtended()
                                    || activity.isStatusOnGoing()) {
                                this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);

                                activityBlock = new Paragraph();
                                activityBlock.setFont(TABLE_BODY_BOLD_FONT);
                                activityBlock.add(this.getText("summaries.project.activities.justification"));

                                activityBlock.setFont(TABLE_BODY_FONT);
                                activityBlock.add(this.messageReturn(activity.getActivityProgress()));
                                activityBlock.add(Chunk.NEWLINE);

                                this.addTableBodyCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1);
                            } else {
                                this.addTableColSpanCell(table, activityBlock, Element.ALIGN_JUSTIFIED, 1, 2);
                            }
                        }

                        // document.add(Chunk.NEWLINE);
                        document.add(table);
                        activityBlock = new Paragraph();
                        activityBlock.add(Chunk.NEWLINE);
                        document.add(activityBlock);
                        counter++;

                    }
                }

            }

            // Leason regardins
            activityBlock = new Paragraph();
            activityBlock.setAlignment(Element.ALIGN_JUSTIFIED);
            activityBlock.setFont(BODY_TEXT_BOLD_FONT);
            if (!project.isReporting()) {
                activityBlock.add(this.getText("summaries.project.activities.lessonsRegarding"));
            } else {
                activityBlock.add(this.getText("summaries.project.activities.reporting.lessonsRegarding"));
            }
            activityBlock.setFont(BODY_TEXT_FONT);

            if (project.getComponentLesson("activities") != null) {
                activityBlock.add(this.messageReturn(project.getComponentLesson("activities").getLessons()));
            } else {
                activityBlock.add(this.messageReturn(null));
            }
            document.add(activityBlock);

        }

    } catch (DocumentException e) {
        LOG.error(
                "There was an error trying to add the project activities to the project summary pdf of project {} ",
                e, project.getId());
    }

}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

private void addBudgetByMogOne(Paragraph paragraph, PdfPTable table, StringBuffer budgetLabel, IPElement mog,
        int startYear, int endYear, BudgetType budgetType) {
    paragraph = new Paragraph();
    budgetLabel = new StringBuffer();
    paragraph.setFont(TABLE_BODY_FONT);// w  w w  .ja  va  2s.c  om
    budgetLabel.append(mog.getProgram().getAcronym());
    budgetLabel.append(" - MOG # ");
    budgetLabel.append(this.getMOGIndex(mog));
    budgetLabel.append(": ");
    budgetLabel.append(mog.getDescription());
    budgetLabel.append(" - " + budgetType.name().replace("_", "/"));
    paragraph.add(budgetLabel.toString());
    this.addCustomTableCell(table, paragraph, Element.ALIGN_JUSTIFIED, BODY_TEXT_FONT, Color.WHITE,
            table.getNumberOfColumns(), 0, false);

    PdfPCell cell;
    // year
    paragraph = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT);
    cell = new PdfPCell(paragraph);
    cell.setRowspan(2);
    this.addTableHeaderCell(table, cell);

    // % de amount
    paragraph = new Paragraph(this.getText("summaries.project.budget.mog.anual.percentaje",
            new String[] { budgetType.name().replace("_", "/") }), TABLE_HEADER_FONT);
    cell = new PdfPCell(paragraph);
    cell.setColspan(2);
    this.addTableHeaderCell(table, cell);

    // gender
    paragraph = new Paragraph(this.getText("summaries.project.budget.mog.anual.gender",
            new String[] { budgetType.name().replace("_", "/") }), TABLE_HEADER_FONT);
    cell = new PdfPCell(paragraph);
    cell.setColspan(2);
    this.addTableHeaderCell(table, cell);

    // amount (%)
    paragraph = new Paragraph("(%)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    // amount (USD)
    paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    // gender (%)
    paragraph = new Paragraph("(%)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    // gender (USD)
    paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT);
    this.addTableHeaderCell(table, paragraph);

    double[] totalsByYear = { 0, 0 };

    for (int year = startYear; year <= endYear; year++) {
        paragraph = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0);
        this.addBudgetMogByYear(year, paragraph, table, mog, budgetType, totalsByYear);
    }

    // Totals
    paragraph = new Paragraph(this.getText("summaries.project.budget.overall.total"), TABLE_BODY_BOLD_FONT);
    this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0);

    // total amount $
    paragraph = new Paragraph(this.budgetFormatter.format(totalsByYear[0]), TABLE_BODY_BOLD_FONT);
    this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2);

    // total gender $
    paragraph = new Paragraph(this.budgetFormatter.format(totalsByYear[1]), TABLE_BODY_BOLD_FONT);
    this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2);

}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

/**
 * @param year year of Budget//from www .j a  v  a 2  s .c  o m
 * @param cell cell of tge table
 * @param table table for to represent the budget MOG
 * @param mog MOG to calculate the budget
 * @param budgetType type budget
 */
private void addBudgetMogByYear(int year, Paragraph cell, PdfPTable table, IPElement mog, BudgetType budgetType,
        double[] totalsByYear) {

    List<OutputBudget> listOutputBudgets = new ArrayList<>();

    listOutputBudgets = budgetByMogManager.getProjectOutputsBudgetByTypeAndYear(project.getId(),
            budgetType.getValue(), year);
    OutputBudget budget_temp = this.getOutputBudgetByMog(listOutputBudgets, mog);

    cell = new Paragraph();
    cell.setFont(TABLE_BODY_FONT);

    if (budget_temp == null) {

        // amount
        cell.add(this.genderFormatter.format(0));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(budgetFormatter.format(0));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        // gender
        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(genderFormatter.format(0));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(budgetFormatter.format(0));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

    } else {
        double value = budget_temp.getTotalContribution() * 0.01;
        // amount %
        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(genderFormatter.format(value));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        // amoun $
        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        value = budget_temp.getTotalContribution() * 0.01 * budgetManager
                .calculateProjectBudgetByTypeAndYear(project.getId(), budgetType.getValue(), year);
        cell.add(budgetFormatter.format(value));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
        totalsByYear[0] += value;

        // Gender %
        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);
        cell.add(this.genderFormatter.format(budget_temp.getGenderContribution() * 0.01));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

        cell = new Paragraph();
        cell.setFont(TABLE_BODY_FONT);

        cell = new Paragraph();
        // Gender $
        cell.setFont(TABLE_BODY_FONT);
        value = budget_temp.getGenderContribution() * 0.01 * budgetManager
                .calculateGenderBudgetByTypeAndYear(project.getId(), budgetType.getValue(), year);
        cell.add(budgetFormatter.format(value));
        this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
        totalsByYear[1] += value;
    }

}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

private void addBudgetReporting(String number) {

    try {/*from   w w  w  . j a v  a2  s .c om*/
        document.newPage();
        Paragraph leverageBlock = new Paragraph(
                number + ". " + this.getText("summaries.project.leverage") + "s", HEADING2_FONT);
        leverageBlock.setAlignment(Element.ALIGN_JUSTIFIED);
        leverageBlock.add(Chunk.NEWLINE);

        PdfPTable table;
        List<ProjectLeverage> listLeverage = project.getLeverages();

        if (listLeverage.isEmpty()) {
            leverageBlock.setFont(BODY_TEXT_FONT);
            leverageBlock.add(this.getText("summaries.project.empty"));
            document.add(leverageBlock);
        } else {
            leverageBlock.add(Chunk.NEWLINE);
            document.add(leverageBlock);
            int counter = 1;
            for (ProjectLeverage leverage : listLeverage) {
                if (leverage != null) {
                    table = new PdfPTable(2);
                    table.setTotalWidth(480);
                    table.setLockedWidth(true);

                    // Header table
                    leverageBlock = new Paragraph();
                    leverageBlock.setAlignment(Element.ALIGN_CENTER);
                    leverageBlock.setFont(TABLE_HEADER_FONT);
                    leverageBlock.add(this.getText("summaries.project.leverage") + " #" + counter);

                    this.addTableHeaderCellColspan(table, leverageBlock, 2);

                    // leverage title
                    leverageBlock = new Paragraph();
                    leverageBlock.setFont(TABLE_BODY_BOLD_FONT);
                    leverageBlock.add(this.getText("summaries.project.activities.title"));

                    leverageBlock.setFont(TABLE_BODY_FONT);
                    leverageBlock.add(this.messageReturn(leverage.getTitle()));
                    leverageBlock.add(Chunk.NEWLINE);
                    this.addTableColSpanCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                    // Leverage institution
                    leverageBlock = new Paragraph();
                    leverageBlock.setFont(TABLE_BODY_BOLD_FONT);
                    leverageBlock.add(this.getText("summaries.project.leverage.partnerName"));

                    leverageBlock.setFont(TABLE_BODY_FONT);
                    if (leverage.getMyInstitution() != null) {
                        leverageBlock.add(this.messageReturn(leverage.getMyInstitution().getComposedName()));
                    } else {
                        leverageBlock.add(this.messageReturn(null));
                    }

                    leverageBlock.add(Chunk.NEWLINE);
                    this.addTableColSpanCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                    // Leverage Year
                    leverageBlock = new Paragraph();
                    leverageBlock.setFont(TABLE_BODY_BOLD_FONT);
                    leverageBlock.add(this.getText("summaries.project.leverage.year"));

                    leverageBlock.setFont(TABLE_BODY_FONT);
                    leverageBlock.add(String.valueOf(this.currentReportingYear));
                    leverageBlock.add(Chunk.NEWLINE);
                    this.addTableColSpanCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1, 2);

                    // Leverage Flagship
                    leverageBlock = new Paragraph();
                    leverageBlock.setFont(TABLE_BODY_BOLD_FONT);
                    leverageBlock.add(this.getText("summaries.project.leverage.flagship"));

                    leverageBlock.setFont(TABLE_BODY_FONT);
                    leverageBlock.add(
                            this.messageReturn(String.valueOf(leverage.getMyFlagship().getComposedName())));
                    leverageBlock.add(Chunk.NEWLINE);
                    this.addTableBodyCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1);

                    // Leverage Budget
                    leverageBlock = new Paragraph();
                    leverageBlock.setFont(TABLE_BODY_BOLD_FONT);
                    leverageBlock.add(this.getText("summaries.project.leverage.budget"));

                    leverageBlock.setFont(TABLE_BODY_FONT);
                    if (leverage.getBudget() != null) {
                        leverageBlock.add("US $");
                        leverageBlock.add(this.budgetFormatter.format(leverage.getBudget().doubleValue()));
                    } else {
                        leverageBlock.add(this.messageReturn(null));
                    }
                    leverageBlock.add(Chunk.NEWLINE);
                    this.addTableBodyCell(table, leverageBlock, Element.ALIGN_JUSTIFIED, 1);

                    document.add(table);
                    leverageBlock = new Paragraph();
                    leverageBlock.add(Chunk.NEWLINE);
                    document.add(leverageBlock);
                    counter++;
                }
            }
            document.add(leverageBlock);
        }
    } catch (DocumentException e) {
        LOG.error(
                "There was an error trying to add the project activities to the project summary pdf of project {} ",
                e, project.getId());
    }

}