Example usage for com.lowagie.text Image getInstance

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

Introduction

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

Prototype

public static Image getInstance(Image image) 

Source Link

Document

gets an instance of an Image

Usage

From source file:org.apache.poi.xwpf.converter.internal.itext.PDFMapper.java

License:Open Source License

@Override
protected void visitPicture(XWPFPicture picture, IITextContainer parentContainer) throws Exception {
    CTPositiveSize2D ext = picture.getCTPicture().getSpPr().getXfrm().getExt();
    long x = ext.getCx();
    long y = ext.getCy();

    CTPicture ctPic = picture.getCTPicture();
    String blipId = ctPic.getBlipFill().getBlip().getEmbed();

    XWPFPictureData pictureData = XWPFPictureUtil.getPictureData(document, blipId);

    if (pictureData != null) {
        try {/*  w w w  . java 2 s.  c o  m*/
            Image img = Image.getInstance(pictureData.getData());
            img.scaleAbsolute(dxa2points(x) / 635, dxa2points(y) / 635);

            IITextContainer parentOfParentContainer = parentContainer.getITextContainer();
            if (parentOfParentContainer != null && parentOfParentContainer instanceof PdfPCell) {
                ((PdfPCell) parentOfParentContainer).setImage(img);
            } else {
                parentContainer.addElement(img);
            }

        } catch (Exception e) {
            LOGGER.severe(e.getMessage());
        }

    }

}

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 . ja  v a  2s.  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.ProjectSummaryPDF.java

License:Open Source License

private void addProjectLocations() {
    Paragraph title = new Paragraph("3. " + this.getText("summaries.projectLocation.title"), HEADING3_FONT);
    Paragraph cell;//from w  w w. j av a  2 s. c  o m
    StringBuffer projectLocations = new StringBuffer();
    List<Location> locationList = (project.getLocations());
    PdfPTable table;
    try {
        document.newPage();
        document.add(title);

        if (project.isGlobal()) {
            Image global = Image.getInstance(config.getBaseUrl() + "/images/summaries/global-map.png");
            global.scalePercent(60f);
            global.setAlignment(Element.ALIGN_CENTER);
            document.add(global);
        } else if (locationList.isEmpty()) {
            cell = new Paragraph();
            cell.setFont(BODY_TEXT_FONT);
            cell.add(this.getText("summaries.project.empty"));
            document.add(cell);
        } else {
            table = new PdfPTable(4);

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

            // Headers
            cell = new Paragraph(this.getText("summaries.projectLocation.table.level"), TABLE_HEADER_FONT);
            this.addTableHeaderCell(table, cell);

            cell = new Paragraph(this.getText("summaries.projectLocation.table.latitude"), TABLE_HEADER_FONT);
            this.addTableHeaderCell(table, cell);

            cell = new Paragraph(this.getText("summaries.projectLocation.table.longitude"), TABLE_HEADER_FONT);
            this.addTableHeaderCell(table, cell);

            cell = new Paragraph(this.getText("summaries.projectLocation.table.name"), TABLE_HEADER_FONT);
            this.addTableHeaderCell(table, cell);
            double answer = 0;
            OtherLocation otherLocation;

            for (Location location : locationList) {
                answer = 0;
                projectLocations = new StringBuffer();
                // Level
                if (location.isCountry()) {
                    projectLocations.append("Country");
                } else if (location.isRegion()) {
                    projectLocations.append("Region");
                } else if (location.isClimateSmartVillage()) {
                    projectLocations.append("CSV");
                } else if (location.isOtherLocation()) {
                    otherLocation = (OtherLocation) location;
                    projectLocations.append(otherLocation.getType().getName());
                }

                cell = new Paragraph();
                cell.setFont(TABLE_BODY_FONT);
                cell.add(projectLocations.toString());
                this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1);

                // Latitude
                projectLocations = new StringBuffer();
                if (location.isOtherLocation()) {
                    otherLocation = (OtherLocation) location;

                    answer = otherLocation.getGeoPosition().getLatitude();

                    cell = new Paragraph();
                    cell.setFont(TABLE_BODY_FONT);
                    if (answer != 0) {
                        cell.add(String.valueOf(answer));
                    } else {
                        cell.add("Not applicable");
                    }
                    this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1);

                    // Longitude
                    answer = otherLocation.getGeoPosition().getLatitude();
                    cell = new Paragraph();
                    cell.setFont(TABLE_BODY_FONT);
                    if (answer != 0) {
                        cell.add(String.valueOf(answer));
                    } else {
                        cell.add("Not applicable");
                    }
                    this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1);

                } else {

                    // Latitude
                    cell = new Paragraph();
                    cell.setFont(TABLE_BODY_FONT);
                    cell.add("Not applicable");
                    this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1);

                    cell = new Paragraph();
                    cell.setFont(TABLE_BODY_FONT);
                    // Longitude
                    cell.add("Not applicable");
                    this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1);
                }

                // Name
                cell = new Paragraph();
                cell.setFont(TABLE_BODY_FONT);
                projectLocations = new StringBuffer();
                projectLocations.append(location.getName());
                cell.add(projectLocations.toString());
                this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1);
            }
            title = new Paragraph();

            title.add(Chunk.NEWLINE);
            title.add(Chunk.NEWLINE);
            document.add(title);
            document.add(table);

            if (!project.isReporting()) {
                // Lesson regarding locations
                Paragraph locationsBlock = new Paragraph();
                locationsBlock.setAlignment(Element.ALIGN_JUSTIFIED);
                locationsBlock.add(Chunk.NEWLINE);
                locationsBlock.add(Chunk.NEWLINE);
                locationsBlock.setFont(BODY_TEXT_BOLD_FONT);
                locationsBlock.add(this.getText("summaries.project.location.lessonRegarding"));
                locationsBlock.setFont(BODY_TEXT_FONT);
                if (project.getComponentLesson("locations") != null) {
                    locationsBlock
                            .add(this.messageReturn(project.getComponentLesson("locations").getLessons()));
                } else {
                    locationsBlock.add(this.messageReturn(null));
                }
                document.add(locationsBlock);
            }
        }

    } catch (DocumentException e) {
        LOG.error("There was an error trying to add the project locations to the project summary pdf", e);
    } catch (MalformedURLException e) {
        LOG.error("There was an error trying to add the project focuses to the project summary pdf", e);
        e.printStackTrace();
    } catch (IOException e) {
        LOG.error("There was an error trying to add the project focuses to the project summary pdf", e);
        e.printStackTrace();
    }

}

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

License:Open Source License

/**
 * Entering the project outputs in the summary
 *///from   w w w.j av a2 s  . com
private void addProjectOutputs(String number) {

    // **********************************************************************************
    // *************************** Overview By Mog *************************************
    // **********************************************************************************
    try {
        Paragraph overview_title = new Paragraph();
        overview_title.setFont(HEADING2_FONT);
        overview_title.add(number + ". " + this.getText("summaries.project.projectOutput"));
        overview_title.add(Chunk.NEWLINE);
        overview_title.add(Chunk.NEWLINE);

        document.newPage();
        document.add(overview_title);

        overview_title = new Paragraph();
        overview_title.setFont(HEADING3_FONT);
        overview_title.add(number + ".1 " + this.getText("summaries.project.overviewbymogs"));
        document.add(overview_title);

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

    int[] years = { midOutcomeYear,
            project.isReporting() ? this.currentReportingYear - 1 : this.currentReportingYear - 1,
            project.isReporting() ? this.currentReportingYear : this.currentPlanningYear,
            project.isReporting() ? this.currentReportingYear + 1 : this.currentReportingYear + 1 };

    Paragraph paragraph = new Paragraph();

    List<IPElement> mogs = project.getOutputs();
    try {
        if (mogs.isEmpty()) {
            paragraph.add(this.getText("summaries.project.empty"));
            document.add(paragraph);

        } else {
            // year
            PdfPTable table;
            for (int a = 0; a < years.length; a++) {
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_HEADER_FONT);
                paragraph.add(this.getText("summaries.project.overviewbymogs.text") + "- " + years[a]);
                table = new PdfPTable(1);
                table.setLockedWidth(true);
                table.setTotalWidth(480);
                this.addTableHeaderCell(table, paragraph);
                // Mog
                for (int b = 0; b < mogs.size(); b++) {
                    this.addOverview(table, mogs.get(b), years[a]);
                }
                paragraph = new Paragraph();
                paragraph.add(Chunk.NEWLINE);
                document.add(paragraph);
                document.add(table);
            }

            // Leason regardins
            paragraph = new Paragraph();
            paragraph.add(Chunk.NEWLINE);
            paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
            paragraph.setFont(BODY_TEXT_BOLD_FONT);
            if (!project.isReporting()) {
                paragraph.add(this.getText("summaries.project.output.lessonRegarding"));
            } else {
                paragraph.add(this.getText("summaries.project.overviewbymogs.reporting.lesson"));
            }
            paragraph.setFont(BODY_TEXT_FONT);
            if (project.getComponentLesson("outputs") != null) {
                paragraph.add(this.messageReturn(project.getComponentLesson("outputs").getLessons()));
            } else {
                paragraph.add(this.messageReturn(null));
            }
            paragraph.add(Chunk.NEWLINE);
            paragraph.add(Chunk.NEWLINE);
            document.add(paragraph);
        }

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

    // **********************************************************************************
    // *************************** Deliverables.****************************************
    // **********************************************************************************

    int counter = 1;
    try {
        document.newPage();
        paragraph = new Paragraph();
        paragraph.setFont(HEADING3_FONT);
        paragraph.add(number + ".2 " + this.getText("summaries.project.deliverable.title"));
        document.add(paragraph);
        paragraph = new Paragraph();

        List<Deliverable> listDeliverables = project.getDeliverables();
        if (listDeliverables.isEmpty()) {
            paragraph.add(this.getText("summaries.project.empty"));
            document.add(paragraph);
        } else {
            paragraph.add(Chunk.NEWLINE);
            document.add(paragraph);
            for (Deliverable deliverable : listDeliverables) {
                if (!project.isReporting()) {
                    if (deliverable.getYear() == config.getPlanningCurrentYear()) {
                        this.addDelivable(deliverable, counter);
                        counter++;

                    }
                }
            }
        }

        // **********************************************************************************
        // *************************** Next users.****************************************
        // **********************************************************************************

        if (project.isReporting()) {

            counter = 1;
            document.newPage();
            paragraph = new Paragraph();
            paragraph.setFont(HEADING3_FONT);
            paragraph.add(number + ".3 " + this.getText("summaries.project.reporting.nextuser.title"));
            document.add(paragraph);

            PdfPTable table;

            if (project.getNextUsers().isEmpty()) {

                paragraph = new Paragraph();
                paragraph.add(this.messageReturn(null));
                paragraph.add(Chunk.NEWLINE);
                document.add(paragraph);

            } else {
                paragraph = new Paragraph();
                paragraph.add(Chunk.NEWLINE);
                document.add(paragraph);

                for (ProjectNextUser projectNextUser : project.getNextUsers()) {

                    paragraph = new Paragraph();
                    paragraph.setFont(TABLE_HEADER_FONT);
                    paragraph.setAlignment(Element.ALIGN_LEFT);

                    table = new PdfPTable(1);
                    table.setLockedWidth(true);
                    table.setTotalWidth(480);

                    paragraph.add(this.getText("summaries.project.reporting.nextuser",
                            new String[] { String.valueOf(counter) }));
                    this.addTableHeaderCell(table, paragraph);

                    // Next users key
                    paragraph = new Paragraph();
                    paragraph.setFont(TABLE_BODY_BOLD_FONT);
                    paragraph.add(this.getText("summaries.project.reporting.nextuser.currentPeriod"));
                    paragraph.setFont(TABLE_BODY_FONT);

                    if (projectNextUser != null) {
                        paragraph.add(this.messageReturn(projectNextUser.getKeyNextUser()));
                    } else {
                        paragraph.add(this.messageReturn(null));
                    }
                    this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                    // Strategies
                    paragraph = new Paragraph();
                    paragraph.setFont(TABLE_BODY_BOLD_FONT);
                    paragraph.add(this.getText("summaries.project.reporting.nextuser.strategies"));
                    paragraph.setFont(TABLE_BODY_FONT);

                    if (projectNextUser != null) {
                        paragraph.add(this.messageReturn(projectNextUser.getStrategies()));
                    } else {
                        paragraph.add(this.messageReturn(null));
                    }
                    this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                    // reported
                    paragraph = new Paragraph();
                    paragraph.setFont(TABLE_BODY_BOLD_FONT);
                    paragraph.add(this.getText("summaries.project.reporting.nextuser.reported"));
                    paragraph.setFont(TABLE_BODY_FONT);

                    if (projectNextUser != null) {
                        paragraph.add(this.messageReturn(projectNextUser.getReportedDeliverables()));
                    } else {
                        paragraph.add(this.messageReturn(null));
                    }
                    this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                    // lessons
                    paragraph = new Paragraph();
                    paragraph.setFont(TABLE_BODY_BOLD_FONT);
                    paragraph.add(this.getText("summaries.project.reporting.nextuser.lessons"));
                    paragraph.setFont(TABLE_BODY_FONT);

                    if (projectNextUser != null) {
                        paragraph.add(this.messageReturn(projectNextUser.getLessonsImplications()));
                    } else {
                        paragraph.add(this.messageReturn(null));
                    }
                    this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                    counter++;
                    document.add(table);
                    paragraph = new Paragraph();
                    paragraph.add(Chunk.NEWLINE);
                    document.add(paragraph);
                }
            }

            // **********************************************************************************
            // *************************** Project HighLights****************************************
            // **********************************************************************************
            counter = 1;
            document.newPage();
            paragraph = new Paragraph();
            paragraph.setFont(HEADING3_FONT);
            paragraph.add(number + ".4 " + this.getText("summaries.project.reporting.highlight.principal"));
            document.add(paragraph);

            paragraph = new Paragraph();
            paragraph.add(Chunk.NEWLINE);
            document.add(paragraph);

            for (ProjectHighligths projectHighLigth : project.getHighlights()) {
                table = new PdfPTable(2);
                table.setLockedWidth(true);
                table.setTotalWidth(480);

                paragraph = new Paragraph();
                paragraph.setFont(TABLE_HEADER_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight",
                        new String[] { String.valueOf(counter) }));
                this.addTableHeaderCellColspan(table, paragraph, 2);

                // title
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.title"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(projectHighLigth.getTitle()));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2);

                // author
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.author"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(projectHighLigth.getAuthor()));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                // subject
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.subject"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(projectHighLigth.getSubject()));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                // publisher
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.publisher"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(projectHighLigth.getPublisher()));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                // year
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.year"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(String.valueOf(projectHighLigth.getYear())));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                // project highlight types
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.types"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    for (ProjectHighligthsTypes projectHighLigthTypes : projectHighLigth
                            .getProjectHighligthsTypeses()) {
                        paragraph.add(this.messageReturn("\n" + ProjectHighlightsType
                                .getEnum(String.valueOf(projectHighLigthTypes.getIdType())).getDescription()));
                    }
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                // project images
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add("Image");

                if (projectHighLigth != null) {
                    Image global;
                    try {
                        if (projectHighLigth.getPhoto() != null) {
                            String urlImage = config.getDownloadURL() + "/" + this.getHighlightsImagesUrlPath()
                                    + projectHighLigth.getPhoto();
                            urlImage = urlImage.replace(" ", "%20");
                            global = Image.getInstance(urlImage);

                        } else {
                            global = null;
                        }

                        if (global != null) {

                            float documentWidth = document.getPageSize().getWidth() - document.leftMargin()
                                    - document.rightMargin();
                            float documentHeight = document.getPageSize().getHeight() - document.topMargin()
                                    - document.bottomMargin();
                            global.scaleToFit((float) (documentWidth * 0.4), global.getHeight());
                            global.setAlignment(Element.ALIGN_CENTER);

                            this.addTableBodyCell(table, global, Element.ALIGN_LEFT, 1);

                        }

                    } catch (MalformedURLException e) {

                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();

                    }

                } else {
                    paragraph.add(this.messageReturn(null));
                }

                // project start date
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.startDate"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(String.valueOf(projectHighLigth.getStartDate())));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                // project end date
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.endDate"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(String.valueOf(projectHighLigth.getEndDate())));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);

                // Its Global
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.itsglobal"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    if (projectHighLigth.isIsGlobal()) {
                        paragraph.add("Yes");
                    } else {
                        paragraph.add("No");
                    }
                    ;
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2);

                // Country
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.country"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null && projectHighLigth.getProjectHighligthsCountries() != null) {
                    for (ProjectHighligthsCountry country : projectHighLigth.getProjectHighligthsCountries()) {
                        paragraph.add(locationManager.getCountry(country.getIdCountry()).getName() + "\n");
                    }
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableBodyCell(table, paragraph, Element.ALIGN_LEFT, 1);
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.keywords"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(projectHighLigth.getKeywords()));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2);

                // description
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.description"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(projectHighLigth.getDescription()));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2);

                // Introduction / Objectives
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.introduction"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(projectHighLigth.getObjectives()));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2);

                // Results
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.results"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(projectHighLigth.getResults()));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2);

                // Partners
                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.partners"));
                paragraph.setFont(TABLE_BODY_FONT);
                if (projectHighLigth != null) {
                    paragraph.add(this.messageReturn(projectHighLigth.getPartners()));
                } else {
                    paragraph.add(this.messageReturn(null));
                }
                this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2);

                // Links

                paragraph = new Paragraph();
                paragraph.setFont(TABLE_BODY_BOLD_FONT);
                paragraph.add(this.getText("summaries.project.reporting.highlight.links"));
                paragraph.setFont(TABLE_BODY_FONT);
                paragraph.add(this.messageReturn(projectHighLigth.getLinks()));

                this.addTableColSpanCell(table, paragraph, Element.ALIGN_LEFT, 1, 2);

                document.add(table);
                document.newPage();
            }

        }
    } 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.marlo.action.summaries.ProjectHighlightsSummaryAction.java

License:Open Source License

private TypedTableModel getProjectHighligthsTableModel() {
    TypedTableModel model = new TypedTableModel(
            new String[] { "id", "title", "author", "subject", "publisher", "year_reported", "highlights_types",
                    "highlights_is_global", "start_date", "end_date", "keywords", "countries", "image",
                    "highlight_desc", "introduction", "results", "partners", "links", "width", "heigth",
                    "project_id", "imageurl", "imageName", "phaseID" },
            new Class[] { Long.class, String.class, String.class, String.class, String.class, Long.class,
                    String.class, String.class, String.class, String.class, String.class, String.class,
                    String.class, String.class, String.class, String.class, String.class, String.class,
                    Integer.class, Integer.class, String.class, String.class, String.class, Long.class },
            0);//from ww w.j  ava  2  s . c  o m
    SimpleDateFormat formatter = new SimpleDateFormat("MMM yyyy");
    for (ProjectHighlight projectHighlight : projectHighLightManager.findAll().stream()
            .filter(ph -> ph.isActive() && ph.getProject() != null && ph.getProject().isActive()
                    && ph.getProjectHighlightInfo(this.getSelectedPhase()) != null
                    && ph.getProjectHighlightInfo().getYear() != null
                    && ph.getProjectHighlightInfo().getYear() == this.getSelectedYear()
                    && ph.getProject().getProjecInfoPhase(this.getSelectedPhase()) != null)
            .sorted((ph1, ph2) -> Long.compare(ph1.getProject().getId(), ph2.getProject().getId()))
            .collect(Collectors.toList())) {
        String title = null, author = null, subject = null, publisher = null, highlightsTypes = "",
                highlightsIsGlobal = null, startDate = null, endDate = null, keywords = null, countries = "",
                highlightDesc = null, introduction = null, results = null, partners = null, links = null,
                projectId = null, image = "", imageurl = null, imageName = null;
        Long yearReported = null;
        int width = 244;
        int heigth = 163;
        if (projectHighlight.getProjectHighlightInfo().getTitle() != null
                && !projectHighlight.getProjectHighlightInfo().getTitle().isEmpty()) {
            title = projectHighlight.getProjectHighlightInfo().getTitle();
        }
        if (projectHighlight.getProjectHighlightInfo().getAuthor() != null
                && !projectHighlight.getProjectHighlightInfo().getAuthor().isEmpty()) {
            author = projectHighlight.getProjectHighlightInfo().getAuthor();
        }
        if (projectHighlight.getProjectHighlightInfo().getSubject() != null
                && !projectHighlight.getProjectHighlightInfo().getSubject().isEmpty()) {
            subject = projectHighlight.getProjectHighlightInfo().getSubject();
        }
        if (projectHighlight.getProjectHighlightInfo().getPublisher() != null
                && !projectHighlight.getProjectHighlightInfo().getPublisher().isEmpty()) {
            publisher = projectHighlight.getProjectHighlightInfo().getPublisher();
        }
        if (projectHighlight.getProjectHighlightInfo().getYear() != null) {
            yearReported = projectHighlight.getProjectHighlightInfo().getYear();
        }
        for (ProjectHighlightType projectHighlightType : projectHighlight.getProjectHighligthsTypes().stream()
                .filter(pht -> pht.isActive()).collect(Collectors.toList())) {
            if (ProjectHighligthsTypeEnum.getEnum(projectHighlightType.getIdType() + "") != null) {
                if (this.getSelectedFormat().equals(APConstants.SUMMARY_FORMAT_EXCEL)) {
                    highlightsTypes += "\n? " + ProjectHighligthsTypeEnum
                            .getEnum(projectHighlightType.getIdType() + "").getDescription();
                } else {
                    highlightsTypes += "<br>? " + ProjectHighligthsTypeEnum
                            .getEnum(projectHighlightType.getIdType() + "").getDescription();
                }
            }
        }
        if (highlightsTypes.isEmpty()) {
            highlightsTypes = null;
        }
        if (projectHighlight.getProjectHighlightInfo().isGlobal() == true) {
            highlightsIsGlobal = "Yes";
        } else {
            highlightsIsGlobal = "No";
        }
        if (projectHighlight.getProjectHighlightInfo().getStartDate() != null) {
            startDate = formatter.format(projectHighlight.getProjectHighlightInfo().getStartDate());
        }
        if (projectHighlight.getProjectHighlightInfo().getEndDate() != null) {
            endDate = formatter.format(projectHighlight.getProjectHighlightInfo().getEndDate());
        }
        if (projectHighlight.getProjectHighlightInfo().getKeywords() != null
                && !projectHighlight.getProjectHighlightInfo().getKeywords().isEmpty()) {
            keywords = projectHighlight.getProjectHighlightInfo().getKeywords();
        }
        int countriesFlag = 0;
        for (ProjectHighlightCountry projectHighlightCountry : projectHighlight.getProjectHighlightCountries()
                .stream().filter(phc -> phc.isActive()).collect(Collectors.toList())) {

            if (projectHighlightCountry.getLocElement() != null) {
                if (countriesFlag == 0) {
                    countries += projectHighlightCountry.getLocElement().getName();
                    countriesFlag++;
                } else {
                    countries += ", " + projectHighlightCountry.getLocElement().getName();
                    countriesFlag++;
                }
            }
        }
        if (countries.isEmpty()) {
            countries = null;
        }
        if (projectHighlight.getProjectHighlightInfo().getDescription() != null
                && !projectHighlight.getProjectHighlightInfo().getDescription().isEmpty()) {
            if (this.getSelectedFormat().equals(APConstants.SUMMARY_FORMAT_EXCEL)) {
                highlightDesc = projectHighlight.getProjectHighlightInfo().getDescription();
            } else {
                highlightDesc = HTMLParser
                        .plainTextToHtml(projectHighlight.getProjectHighlightInfo().getDescription());
            }
        }
        if (projectHighlight.getProjectHighlightInfo().getObjectives() != null
                && !projectHighlight.getProjectHighlightInfo().getObjectives().isEmpty()) {
            if (this.getSelectedFormat().equals(APConstants.SUMMARY_FORMAT_EXCEL)) {
                introduction = projectHighlight.getProjectHighlightInfo().getObjectives();
            } else {
                introduction = HTMLParser
                        .plainTextToHtml(projectHighlight.getProjectHighlightInfo().getObjectives());
            }
        }
        if (projectHighlight.getProjectHighlightInfo().getResults() != null
                && !projectHighlight.getProjectHighlightInfo().getResults().isEmpty()) {
            if (this.getSelectedFormat().equals(APConstants.SUMMARY_FORMAT_EXCEL)) {
                results = projectHighlight.getProjectHighlightInfo().getResults();
            } else {
                results = HTMLParser.plainTextToHtml(projectHighlight.getProjectHighlightInfo().getResults());
            }
        }
        if (projectHighlight.getProjectHighlightInfo().getPartners() != null
                && !projectHighlight.getProjectHighlightInfo().getPartners().isEmpty()) {
            if (this.getSelectedFormat().equals(APConstants.SUMMARY_FORMAT_EXCEL)) {
                partners = projectHighlight.getProjectHighlightInfo().getPartners();
            } else {
                partners = HTMLParser.plainTextToHtml(projectHighlight.getProjectHighlightInfo().getPartners());
            }
        }
        if (projectHighlight.getProjectHighlightInfo().getLinks() != null
                && !projectHighlight.getProjectHighlightInfo().getLinks().isEmpty()) {
            if (this.getSelectedFormat().equals(APConstants.SUMMARY_FORMAT_EXCEL)) {
                links = projectHighlight.getProjectHighlightInfo().getLinks();
            } else {
                links = HTMLParser.plainTextToHtml(projectHighlight.getProjectHighlightInfo().getLinks());
            }
        }
        if (projectHighlight.getProject() != null) {
            projectId = projectHighlight.getProject().getId().toString();
        }
        if (projectHighlight.getProjectHighlightInfo().getFile() != null) {
            double pageWidth = 612 * 0.4;
            double pageHeigth = 792 * 0.4;
            double imageWidth = 244;
            double imageHeigth = 163;
            image = this.getHightlightImagePath(projectHighlight.getProject().getId())
                    + projectHighlight.getProjectHighlightInfo().getFile().getFileName();
            imageurl = this.getHighlightsImagesUrl(projectHighlight.getProject().getId().toString())
                    + projectHighlight.getProjectHighlightInfo().getFile().getFileName();
            imageName = projectHighlight.getProjectHighlightInfo().getFile().getFileName();
            Image imageFile = null;
            LOG.info("image.getURL.replace " + image);
            File url;
            try {
                url = new File(image);
            } catch (Exception e) {
                LOG.warn("Failed to get image File. Url was set to null. Exception: " + e.getMessage());
                url = null;
                image = "";
                imageurl = null;
                imageName = null;
            }
            if (url != null && url.exists()) {
                try {
                    imageFile = Image.getInstance(FileManager.readURL(url));
                    // System.out.println("W: " + imageFile.getWidth() + " \nH: " + imageFile.getHeight());
                    if (imageFile.getWidth() >= imageFile.getHeight()) {
                        imageWidth = pageWidth;
                        imageHeigth = imageFile.getHeight()
                                * (((pageWidth * 100) / imageFile.getWidth()) / 100);
                    } else {
                        imageHeigth = pageHeigth;
                        imageWidth = imageFile.getWidth()
                                * (((pageHeigth * 100) / imageFile.getHeight()) / 100);
                    }
                    // System.out.println("New W: " + imageWidth + " \nH: " + imageHeigth);
                    width = (int) imageWidth;
                    heigth = (int) imageHeigth;
                    // If successful, process the message
                } catch (BadElementException e) {
                    LOG.warn("BadElementException getting image: " + e.getMessage());
                    image = "";
                    imageurl = null;
                    imageName = null;
                } catch (MalformedURLException e) {
                    LOG.warn("MalformedURLException getting image: " + e.getMessage());
                    image = "";
                    imageurl = null;
                    imageName = null;
                } catch (IOException e) {
                    LOG.warn("IOException getting image: " + e.getMessage());
                    image = "";
                    imageurl = null;
                    imageName = null;
                }
            } else {
                image = "";
                imageurl = null;
                imageName = null;
            }
        }
        Long phaseID = this.getSelectedPhase().getId();
        model.addRow(new Object[] { projectHighlight.getId(), title, author, subject, publisher, yearReported,
                highlightsTypes, highlightsIsGlobal, startDate, endDate, keywords, countries, image,
                highlightDesc, introduction, results, partners, links, width, heigth, projectId, imageurl,
                imageName, phaseID });
    }
    return model;
}

From source file:org.cgiar.ccafs.marlo.action.summaries.ProjectHighlightSummaryAction.java

License:Open Source License

private TypedTableModel getProjectHighligthsTableModel() {
    TypedTableModel model = new TypedTableModel(
            new String[] { "id", "title", "author", "subject", "publisher", "year_reported", "highlights_types",
                    "highlights_is_global", "start_date", "end_date", "keywords", "countries", "image",
                    "highlight_desc", "introduction", "results", "partners", "links", "width", "heigth",
                    "project_id", "imageurl", "imageName", "phaseID" },
            new Class[] { Long.class, String.class, String.class, String.class, String.class, Long.class,
                    String.class, String.class, String.class, String.class, String.class, String.class,
                    String.class, String.class, String.class, String.class, String.class, String.class,
                    Integer.class, Integer.class, String.class, String.class, String.class, Long.class },
            0);/*from   w  w  w . j  ava 2  s. c om*/
    SimpleDateFormat formatter = new SimpleDateFormat("MMM yyyy");
    String title = null, author = null, subject = null, publisher = null, highlightsTypes = "",
            highlightsIsGlobal = null, startDate = null, endDate = null, keywords = null, countries = "",
            highlightDesc = null, introduction = null, results = null, partners = null, links = null,
            project = null, image = "", imageurl = null, imageName = null;
    Long yearReported = null;
    int width = 244;
    int heigth = 163;
    if (projectHighlightInfo.getTitle() != null && !projectHighlightInfo.getTitle().isEmpty()) {
        title = projectHighlightInfo.getTitle();
    }
    if (projectHighlightInfo.getAuthor() != null && !projectHighlightInfo.getAuthor().isEmpty()) {
        author = projectHighlightInfo.getAuthor();
    }
    if (projectHighlightInfo.getSubject() != null && !projectHighlightInfo.getSubject().isEmpty()) {
        subject = projectHighlightInfo.getSubject();
    }
    if (projectHighlightInfo.getPublisher() != null && !projectHighlightInfo.getPublisher().isEmpty()) {
        publisher = projectHighlightInfo.getPublisher();
    }
    if (projectHighlightInfo.getYear() != null) {
        yearReported = projectHighlightInfo.getYear();
    }
    for (ProjectHighlightType projectHighlightType : projectHighlightInfo.getProjectHighlight()
            .getProjectHighligthsTypes().stream().filter(pht -> pht.isActive()).collect(Collectors.toList())) {
        if (ProjectHighligthsTypeEnum.getEnum(projectHighlightType.getIdType() + "") != null) {
            highlightsTypes += "<br>? "
                    + ProjectHighligthsTypeEnum.getEnum(projectHighlightType.getIdType() + "").getDescription();
        }
    }
    if (highlightsTypes.isEmpty()) {
        highlightsTypes = null;
    }
    if (projectHighlightInfo.isGlobal() == true) {
        highlightsIsGlobal = "Yes";
    } else {
        highlightsIsGlobal = "No";
    }
    if (projectHighlightInfo.getStartDate() != null) {
        startDate = formatter.format(projectHighlightInfo.getStartDate());
    }
    if (projectHighlightInfo.getEndDate() != null) {
        endDate = formatter.format(projectHighlightInfo.getEndDate());
    }
    if (projectHighlightInfo.getKeywords() != null && !projectHighlightInfo.getKeywords().isEmpty()) {
        keywords = projectHighlightInfo.getKeywords();
    }
    int countriesFlag = 0;
    for (ProjectHighlightCountry projectHighlightCountry : projectHighlightInfo.getProjectHighlight()
            .getProjectHighlightCountries().stream().filter(phc -> phc.isActive())
            .collect(Collectors.toList())) {

        if (projectHighlightCountry.getLocElement() != null) {
            if (countriesFlag == 0) {
                countries += projectHighlightCountry.getLocElement().getName();
                countriesFlag++;
            } else {
                countries += ", " + projectHighlightCountry.getLocElement().getName();
                countriesFlag++;
            }
        }
    }
    if (countries.isEmpty()) {
        countries = null;
    }
    if (projectHighlightInfo.getDescription() != null && !projectHighlightInfo.getDescription().isEmpty()) {
        highlightDesc = HTMLParser.plainTextToHtml(projectHighlightInfo.getDescription());
    }
    if (projectHighlightInfo.getObjectives() != null && !projectHighlightInfo.getObjectives().isEmpty()) {
        introduction = HTMLParser.plainTextToHtml(projectHighlightInfo.getObjectives());
    }
    if (projectHighlightInfo.getResults() != null && !projectHighlightInfo.getResults().isEmpty()) {
        results = HTMLParser.plainTextToHtml(projectHighlightInfo.getResults());
    }
    if (projectHighlightInfo.getPartners() != null && !projectHighlightInfo.getPartners().isEmpty()) {
        partners = HTMLParser.plainTextToHtml(projectHighlightInfo.getPartners());
    }
    if (projectHighlightInfo.getLinks() != null && !projectHighlightInfo.getLinks().isEmpty()) {
        links = HTMLParser.plainTextToHtml(projectHighlightInfo.getLinks());
    }
    if (projectHighlightInfo.getProjectHighlight().getProject() != null && projectHighlightInfo
            .getProjectHighlight().getProject().getProjecInfoPhase(this.getSelectedPhase()) != null) {
        project = projectHighlightInfo.getProjectHighlight().getProject().getComposedName();
    }
    if (projectHighlightInfo.getFile() != null) {
        double pageWidth = 612 * 0.4;
        double pageHeigth = 792 * 0.4;
        double imageWidth = 244;
        double imageHeigth = 163;
        image = this.getHightlightImagePath(projectHighlightInfo.getProjectHighlight().getProject().getId())
                + projectHighlightInfo.getFile().getFileName();
        imageurl = this.getHighlightsImagesUrl(
                projectHighlightInfo.getProjectHighlight().getProject().getId().toString())
                + projectHighlightInfo.getFile().getFileName();
        imageName = projectHighlightInfo.getFile().getFileName();
        Image imageFile = null;
        LOG.info("image.getURL.replace " + image);
        File url;
        try {
            url = new File(image);
        } catch (Exception e) {
            LOG.warn("Failed to get image File. Url was set to null. Exception: " + e.getMessage());
            url = null;
            image = "";
            imageurl = null;
            imageName = null;
        }
        if (url != null && url.exists()) {
            try {
                imageFile = Image.getInstance(FileManager.readURL(url));
                // System.out.println("W: " + imageFile.getWidth() + " \nH: " + imageFile.getHeight());
                if (imageFile.getWidth() >= imageFile.getHeight()) {
                    imageWidth = pageWidth;
                    imageHeigth = imageFile.getHeight() * (((pageWidth * 100) / imageFile.getWidth()) / 100);
                } else {
                    imageHeigth = pageHeigth;
                    imageWidth = imageFile.getWidth() * (((pageHeigth * 100) / imageFile.getHeight()) / 100);
                }
                // System.out.println("New W: " + imageWidth + " \nH: " + imageHeigth);
                width = (int) imageWidth;
                heigth = (int) imageHeigth;
                // If successful, process the message
            } catch (BadElementException e) {
                LOG.warn("BadElementException getting image: " + e.getMessage());
                image = "";
                imageurl = null;
                imageName = null;
            } catch (MalformedURLException e) {
                LOG.warn("MalformedURLException getting image: " + e.getMessage());
                image = "";
                imageurl = null;
                imageName = null;
            } catch (IOException e) {
                LOG.warn("IOException getting image: " + e.getMessage());
                image = "";
                imageurl = null;
                imageName = null;
            }
        } else {
            image = "";
            imageurl = null;
            imageName = null;
        }
    }
    Long phaseID = this.getSelectedPhase().getId();
    model.addRow(new Object[] { projectHighlightID, title, author, subject, publisher, yearReported,
            highlightsTypes, highlightsIsGlobal, startDate, endDate, keywords, countries, image, highlightDesc,
            introduction, results, partners, links, width, heigth, project, imageurl, imageName, phaseID });
    return model;
}

From source file:org.cgiar.ccafs.marlo.action.summaries.ReportingSummaryAction.java

License:Open Source License

private TypedTableModel getProjectHighlightReportingTableModel() {
    TypedTableModel model = new TypedTableModel(
            new String[] { "id", "title", "author", "subject", "publisher", "year_reported", "highlights_types",
                    "highlights_is_global", "start_date", "end_date", "keywords", "countries", "image",
                    "highlight_desc", "introduction", "results", "partners", "links", "width", "heigth",
                    "isGlobal", "imageurl" },
            new Class[] { Long.class, String.class, String.class, String.class, String.class, Long.class,
                    String.class, String.class, String.class, String.class, String.class, String.class,
                    String.class, String.class, String.class, String.class, String.class, String.class,
                    Integer.class, Integer.class, Boolean.class, String.class },
            0);/*ww  w .ja v a2  s.c o  m*/
    SimpleDateFormat formatter = new SimpleDateFormat("MMM yyyy");
    for (ProjectHighlight projectHighlight : project.getProjectHighligths().stream()
            .sorted((h1, h2) -> Long.compare(h1.getId(), h2.getId()))
            .filter(ph -> ph.getProjectHighlightInfo(this.getSelectedPhase()) != null && ph.isActive()
                    && ph.getProjectHighlightInfo().getYear() != null
                    && ph.getProjectHighlightInfo().getYear() == this.getSelectedYear())
            .collect(Collectors.toList())) {
        String title = null, author = null, subject = null, publisher = null, highlightsTypes = "",
                highlightsIsGlobal = null, startDate = null, endDate = null, keywords = null, countries = "",
                image = "", highlightDesc = null, introduction = null, results = null, partners = null,
                links = null, imageurl = null;
        Long yearReported = null;
        Boolean isGlobal = false;
        int width = 0;
        int heigth = 0;
        if (projectHighlight.getProjectHighlightInfo().getTitle() != null
                && !projectHighlight.getProjectHighlightInfo().getTitle().isEmpty()) {
            title = projectHighlight.getProjectHighlightInfo().getTitle();
        }
        if (projectHighlight.getProjectHighlightInfo().getAuthor() != null
                && !projectHighlight.getProjectHighlightInfo().getAuthor().isEmpty()) {
            author = projectHighlight.getProjectHighlightInfo().getAuthor();
        }
        if (projectHighlight.getProjectHighlightInfo().getSubject() != null
                && !projectHighlight.getProjectHighlightInfo().getSubject().isEmpty()) {
            subject = projectHighlight.getProjectHighlightInfo().getSubject();
        }
        if (projectHighlight.getProjectHighlightInfo().getPublisher() != null
                && !projectHighlight.getProjectHighlightInfo().getPublisher().isEmpty()) {
            publisher = projectHighlight.getProjectHighlightInfo().getPublisher();
        }
        if (projectHighlight.getProjectHighlightInfo().getYear() != null) {
            yearReported = projectHighlight.getProjectHighlightInfo().getYear();
        }
        for (ProjectHighlightType projectHighlightType : projectHighlight.getProjectHighligthsTypes().stream()
                .filter(pht -> pht.isActive()).collect(Collectors.toList())) {
            if (ProjectHighligthsTypeEnum.getEnum(projectHighlightType.getIdType() + "") != null) {
                highlightsTypes += "<br>? " + ProjectHighligthsTypeEnum
                        .getEnum(projectHighlightType.getIdType() + "").getDescription();
            }
        }
        if (highlightsTypes.isEmpty()) {
            highlightsTypes = null;
        }
        if (projectHighlight.getProjectHighlightInfo().isGlobal() == true) {
            isGlobal = true;
            highlightsIsGlobal = "Yes";
        } else {
            highlightsIsGlobal = "No";
        }
        if (projectHighlight.getProjectHighlightInfo().getStartDate() != null) {
            startDate = formatter.format(projectHighlight.getProjectHighlightInfo().getStartDate());
        }
        if (projectHighlight.getProjectHighlightInfo().getEndDate() != null) {
            endDate = formatter.format(projectHighlight.getProjectHighlightInfo().getEndDate());
        }
        if (projectHighlight.getProjectHighlightInfo().getKeywords() != null
                && !projectHighlight.getProjectHighlightInfo().getKeywords().isEmpty()) {
            keywords = projectHighlight.getProjectHighlightInfo().getKeywords();
        }
        int countriesFlag = 0;
        for (ProjectHighlightCountry projectHighlightCountry : projectHighlight.getProjectHighlightCountries()
                .stream().filter(phc -> phc.isActive()).collect(Collectors.toList())) {
            if (projectHighlightCountry.getLocElement() != null) {
                if (countriesFlag == 0) {
                    countries += projectHighlightCountry.getLocElement().getName();
                    countriesFlag++;
                } else {
                    countries += ", " + projectHighlightCountry.getLocElement().getName();
                    countriesFlag++;
                }
            }
        }
        if (countries.isEmpty()) {
            countries = null;
        }
        if (projectHighlight.getProjectHighlightInfo().getFile() != null) {
            double pageWidth = 612 * 0.4;
            double pageHeigth = 792 * 0.4;
            double imageWidth = 0;
            double imageHeigth = 0;
            image = this.getHightlightImagePath(projectHighlight.getProject().getId())
                    + projectHighlight.getProjectHighlightInfo().getFile().getFileName();
            imageurl = this.getHighlightsImagesUrl(projectHighlight.getProject().getId().toString())
                    + projectHighlight.getProjectHighlightInfo().getFile().getFileName();
            Image imageFile = null;
            LOG.info("Image name: " + image);
            File url;
            try {
                url = new File(image);
            } catch (Exception e) {
                LOG.warn("Failed to get image File. Url was set to null. Exception: " + e.getMessage());
                url = null;
                image = "";
                imageurl = null;
            }
            if (url != null && url.exists()) {
                // System.out.println("Project: " + projectHighlight.getProject().getId() + " PH: " +
                // projectHighlight.getId());
                try {
                    imageFile = Image.getInstance(FileManager.readURL(url));
                    // System.out.println("W: " + imageFile.getWidth() + " \nH: " + imageFile.getHeight());
                    if (imageFile.getWidth() >= imageFile.getHeight()) {
                        imageWidth = pageWidth;
                        imageHeigth = imageFile.getHeight()
                                * (((pageWidth * 100) / imageFile.getWidth()) / 100);
                    } else {
                        imageHeigth = pageHeigth;
                        imageWidth = imageFile.getWidth()
                                * (((pageHeigth * 100) / imageFile.getHeight()) / 100);
                    }
                    // System.out.println("New W: " + imageWidth + " \nH: " + imageHeigth);
                    width = (int) imageWidth;
                    heigth = (int) imageHeigth;
                    // If successful, process the message
                } catch (BadElementException e) {
                    LOG.warn("BadElementException getting image: " + e.getMessage());
                    image = "";
                } catch (MalformedURLException e) {
                    LOG.warn("MalformedURLException getting image: " + e.getMessage());
                    image = "";
                    imageurl = null;
                } catch (IOException e) {
                    LOG.warn("IOException getting image: " + e.getMessage());
                    image = "";
                    imageurl = null;
                }
            } else {
                image = "";
                imageurl = null;
            }
        }
        if (projectHighlight.getProjectHighlightInfo().getDescription() != null
                && !projectHighlight.getProjectHighlightInfo().getDescription().isEmpty()) {
            highlightDesc = projectHighlight.getProjectHighlightInfo().getDescription();
        }
        if (projectHighlight.getProjectHighlightInfo().getObjectives() != null
                && !projectHighlight.getProjectHighlightInfo().getObjectives().isEmpty()) {
            introduction = projectHighlight.getProjectHighlightInfo().getObjectives();
        }
        if (projectHighlight.getProjectHighlightInfo().getResults() != null
                && !projectHighlight.getProjectHighlightInfo().getResults().isEmpty()) {
            results = projectHighlight.getProjectHighlightInfo().getResults();
        }
        if (projectHighlight.getProjectHighlightInfo().getPartners() != null
                && !projectHighlight.getProjectHighlightInfo().getPartners().isEmpty()) {
            partners = projectHighlight.getProjectHighlightInfo().getPartners();
        }
        if (projectHighlight.getProjectHighlightInfo().getLinks() != null
                && !projectHighlight.getProjectHighlightInfo().getLinks().isEmpty()) {
            links = projectHighlight.getProjectHighlightInfo().getLinks();
        }
        model.addRow(new Object[] { projectHighlight.getId(), title, author, subject, publisher, yearReported,
                highlightsTypes, highlightsIsGlobal, startDate, endDate, keywords, countries, image,
                highlightDesc, introduction, results, partners, links, width, heigth, isGlobal, imageurl });
    }
    return model;
}

From source file:org.cyberoam.iview.charts.Chart.java

License:Open Source License

/**
 * Function to write a given ChartID to pdf file
 * @param pdfFileName specifies the pdf where chart is written.Please specify full path with the filename.
 * @param reportGroup id specifies the chart to be generated
 * @param startdate specifies start date 
 * @param enddate specifies end date/* w  w w  .  ja v a2  s .  co  m*/
 * @param limit specifies number of records per record to be written in report
 */
public static void generatePDFReportGroup(OutputStream out, int reportGroupID, String applianceID,
        String startDate, String endDate, String limit, int[] deviceIDs, HttpServletRequest request,
        LinkedHashMap paramMap) throws Exception {
    float width = 768;
    float height = 1024;
    float rec_hieght = 470;
    Rectangle pagesize = new Rectangle(768, 1024);
    Document document = new Document(pagesize, 30, 30, 30, 30);

    JFreeChart chart = null;
    SqlReader sqlReader = new SqlReader(false);
    //CyberoamLogger.sysLog.debug("pdf:"+pdfFileName);
    CyberoamLogger.sysLog.debug("reportGroupID:" + reportGroupID);
    CyberoamLogger.sysLog.debug("applianceID:" + applianceID);
    CyberoamLogger.sysLog.debug("startDate:" + startDate);
    CyberoamLogger.sysLog.debug("endDate:" + endDate);
    CyberoamLogger.sysLog.debug("limit:" + limit);
    try {
        //PdfWriter writer = PdfWriter.getInstance(document, response!=null ? response.getOutputStream():new FileOutputStream(pdfFileName));
        PdfWriter writer = PdfWriter.getInstance(document, out);
        writer.setPageEvent(new Chart());
        document.addAuthor("iView");
        document.addSubject("iView Report");
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();
        ReportGroupBean reportGroupBean = ReportGroupBean.getRecordbyPrimarykey(reportGroupID);
        ArrayList reportList = reportGroupBean.getReportIdByReportGroupId(reportGroupID);
        ReportBean reportBean;
        ResultSetWrapper rsw = null;

        String seperator = System.getProperty("file.separator");

        //String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator + "iViewPDF.jpg";
        String path = InitServlet.contextPath + seperator + "images" + seperator + "iViewPDF.jpg";

        Image iViewImage = Image.getInstance(path);
        iViewImage.scaleAbsolute(750, 900);
        //iViewImage.scaleAbsolute(600,820);
        iViewImage.setAbsolutePosition(10, 10);
        document.add(iViewImage);

        document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"));

        /*
         *   Generating Table on the First Page of Report providing summary of Content 
         */
        PdfPTable frontPageTable = new PdfPTable(2);
        PdfPCell dataCell;
        ReportGroupRelationBean reportGroupRelationBean;
        String reportName = "";

        Color tableHeadBackColor = new Color(150, 174, 190);
        Color tableContentBackColor = new Color(229, 232, 237);
        Color tableBorderColor = new Color(229, 232, 237);

        dataCell = new PdfPCell(new Phrase(new Chunk("Report Profile",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.PLAIN, new Color(255, 255, 255)))));
        dataCell.setBackgroundColor(tableHeadBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        /**
         * Getting dynamic title.
         */
        String title = "";
        if (paramMap != null) {
            title = paramMap.get("title").toString();

            paramMap.remove("title");
        }
        if (request != null)
            title = getFormattedTitle(request, reportGroupBean, true);

        dataCell = new PdfPCell(new Phrase(new Chunk(title,
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.PLAIN, new Color(255, 255, 255)))));
        dataCell.setBackgroundColor(tableHeadBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(new Chunk("Start Date",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0)))));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(startDate));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(new Chunk("End Date",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0)))));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(endDate));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(new Chunk("iView Server Time",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0)))));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        java.util.Date currentDate = new java.util.Date();
        dataCell = new PdfPCell(new Phrase(currentDate.toString()));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(new Chunk("Reports",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0)))));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        int len = reportList.size();
        for (int k = 0; k < len; k++) {
            reportGroupRelationBean = (ReportGroupRelationBean) reportList.get(k);
            reportName += " " + (k + 1) + ". "
                    + ReportBean.getRecordbyPrimarykey(reportGroupRelationBean.getReportId()).getTitle() + "\n";
        }
        dataCell = new PdfPCell(new Phrase("\n" + reportName + "\n"));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);

        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(new Chunk("Device Names (IP Address)",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0)))));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        DeviceBean deviceBean = null;
        String deviceNameWithIP = "";
        if (deviceIDs != null) {
            for (int i = 0; i < deviceIDs.length; i++) {
                deviceBean = DeviceBean.getRecordbyPrimarykey(deviceIDs[i]);
                if (deviceBean != null) {
                    deviceNameWithIP += " " + (i + 1) + ". " + deviceBean.getName() + " (" + deviceBean.getIp()
                            + ")\n";
                }
            }
        }
        dataCell = new PdfPCell(new Phrase("\n" + deviceNameWithIP + "\n"));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        /*
         * Adding Table to PDF      
         */
        document.add(frontPageTable);

        /*
         * Adding Charts and Table to PDF 
         */
        for (int i = 0; i < reportList.size(); i++) {
            document.newPage();
            reportBean = ReportBean
                    .getRecordbyPrimarykey(((ReportGroupRelationBean) reportList.get(i)).getReportId());
            String query = null;
            if (request == null) {
                query = PrepareQuery.getQuery(reportBean, startDate, endDate, applianceID, null, null, "0",
                        limit, paramMap);
            } else {
                PrepareQuery prepareQuery = new PrepareQuery();
                query = prepareQuery.getQuery(reportBean, request);
            }
            CyberoamLogger.sysLog.debug("PDF:ReportID:" + reportBean.getReportId() + "Query->" + query);

            try {
                rsw = sqlReader.getInstanceResultSetWrapper(query);
            } catch (org.postgresql.util.PSQLException e) {
                if (query.indexOf("5min_ts_20") > -1) {
                    query = query.substring(0, query.indexOf("5min_ts_20")) + "4hr"
                            + query.substring(query.indexOf("5min_ts_20") + 16, query.length());
                    CyberoamLogger.appLog.debug("New query : " + query);
                    rsw = sqlReader.getInstanceResultSetWrapper(query);

                } else {
                    CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e);
                }
            } catch (Exception e) {
                CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e);
                rsw.close();
            }

            /*
             * PDF Rendering work starts here
             */

            for (int j = 0; j < (int) (rec_hieght / 16) + 1; j++) {
                document.add(new Paragraph("\n"));
            }
            // This fix is to resolve the problems associated with reports which don't have graphs.
            // If there is no graph associated with the report than no need to generate 
            //a chart for it.
            GraphBean graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getReportId());
            //if(graphBean!=null)
            if (reportBean.getReportFormatId() != 2) {
                chart = Chart.getChart(reportBean.getReportId(), rsw, null);
                PdfTemplate pdfTemplate = contentByte.createTemplate(width, height);
                Graphics2D graphics2D = pdfTemplate.createGraphics(width, height);
                Rectangle2D rectangle = new Rectangle2D.Double(100, 85, 540, rec_hieght);
                chart.draw(graphics2D, rectangle);
                graphics2D.dispose();
                contentByte.addTemplate(pdfTemplate, 0, 0);
            } else {
                Paragraph p = new Paragraph(reportBean.getTitle() + "\n\n",
                        FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD));
                p.setAlignment("center");
                document.add(p);
            }

            // Retrieving PdfPTable
            PdfPTable pdfTable = getPdfPTable(reportBean, rsw);
            rsw.close();

            /*
             * Adding Table to PDF
             */

            document.add(pdfTable);
        }
        CyberoamLogger.appLog.info("*************Finishing Chart****************");
    } catch (Exception e) {
        CyberoamLogger.sysLog.debug("Chart.writeChartToPDF.e" + e.getMessage(), e);
    } finally {
        sqlReader.close();
    }

    document.close();
}

From source file:org.cyberoam.iview.charts.Chart.java

License:Open Source License

public static void generatePDFReport(OutputStream out, int reportID, String applianceID, String startDate,
        String endDate, String limit, int[] deviceIDs, HttpServletRequest request, int reportGroupID,
        LinkedHashMap paramMap) throws Exception {
    float width = 768;
    float height = 1024;
    float rec_hieght = 470;
    Rectangle pagesize = new Rectangle(768, 1024);
    Document document = new Document(pagesize, 30, 30, 30, 30);
    IndexManager indexManager = null;/*from   www.j  a  v a2  s  .  c  om*/
    JFreeChart chart = null;
    SqlReader sqlReader = new SqlReader(false);
    CyberoamLogger.sysLog.debug("reportID:" + reportID);
    CyberoamLogger.sysLog.debug("applianceID:" + applianceID);
    CyberoamLogger.sysLog.debug("startDate:" + startDate);
    CyberoamLogger.sysLog.debug("endDate:" + endDate);
    CyberoamLogger.sysLog.debug("limit:" + limit);

    try {
        //PdfWriter writer = PdfWriter.getInstance(document, response!=null ? response.getOutputStream():new FileOutputStream(pdfFileName));         
        PdfWriter writer = PdfWriter.getInstance(document, out);
        writer.setPageEvent(new Chart());
        document.addAuthor("iView");
        document.addSubject("iView Report");
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();
        //ReportGroupBean reportGroupBean=ReportGroupBean.getRecordbyPrimarykey(reportGroupID);

        //ArrayList reportList=reportGroupBean.getReportIdByReportGroupId(reportGroupID);          
        ReportBean reportBean;
        ResultSetWrapper rsw = null;

        String seperator = System.getProperty("file.separator");
        //         String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator; 
        String path = InitServlet.contextPath + seperator + "images" + seperator + "iViewPDF.jpg";
        /*          
         *   Loading Image to add into PDF 
         */

        Image iViewImage = Image.getInstance(path);
        iViewImage.scaleAbsolute(750, 900);
        //iViewImage.scaleAbsolute(600,820);
        iViewImage.setAbsolutePosition(10, 10);

        /*Image headerImage= Image.getInstance(path+ "iViewPDFHeader.jpg");
                
        PdfPTable headerTable = new PdfPTable(2);
        PdfPCell cell = new PdfPCell(headerImage);
        headerTable.addCell(cell);         
        HeaderFooter docHeader=null;         
        //document.setHeader(new HeaderFooter(new Phrase(new Chunk())), true);
        */
        document.add(iViewImage);

        document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"));

        /*
         *   Generating Table on the First Page of Report providing summary of Content 
         */
        PdfPTable frontPageTable = new PdfPTable(2);

        PdfPCell dataCell;
        String reportName = "";

        Color tableHeadBackColor = new Color(150, 174, 190);
        Color tableContentBackColor = new Color(229, 232, 237);
        Color tableBorderColor = new Color(229, 232, 237);

        dataCell = new PdfPCell(new Phrase(new Chunk("Report Profile",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 16, Font.PLAIN, new Color(255, 255, 255)))));
        dataCell.setBackgroundColor(tableHeadBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);
        if (paramMap != null) {
            reportName = paramMap.get("title").toString();
            paramMap.remove("title");
        }
        if (request != null) {
            ReportGroupBean reportGroupBean = ReportGroupBean.getRecordbyPrimarykey(reportGroupID);
            reportName = getFormattedTitle(request, reportGroupBean, true);
        }
        dataCell = new PdfPCell();

        dataCell.addElement(new Phrase(new Chunk(reportName,
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(255, 255, 255)))));
        //dataCell.addElement(new Phrase(new Chunk(ReportBean.getRecordbyPrimarykey(reportID).getTitle(), FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11, Font.PLAIN, new Color(10,10,10)))));
        if (request != null) {
            dataCell.addElement(new Phrase(new Chunk(reportName + " >> ", FontFactory
                    .getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(255, 255, 255)))));
            dataCell.addElement(
                    new Phrase(new Chunk(ReportBean.getRecordbyPrimarykey(reportID).getTitle(), FontFactory
                            .getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(255, 255, 255)))));
        }
        dataCell.setBackgroundColor(tableHeadBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(new Chunk("Start Date",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0)))));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(startDate));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(new Chunk("End Date",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0)))));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(endDate));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(new Chunk("iView Server Time",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0)))));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        java.util.Date currentDate = new java.util.Date();
        dataCell = new PdfPCell(new Phrase(currentDate.toString()));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        dataCell = new PdfPCell(new Phrase(new Chunk("Device Names (IP Address)",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 12, Font.PLAIN, new Color(0, 0, 0)))));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        DeviceBean deviceBean = null;
        String deviceNameWithIP = "";
        if (deviceIDs != null) {
            for (int i = 0; i < deviceIDs.length; i++) {
                deviceBean = DeviceBean.getRecordbyPrimarykey(deviceIDs[i]);
                if (deviceBean != null) {
                    deviceNameWithIP += " " + (i + 1) + ". " + deviceBean.getName() + " (" + deviceBean.getIp()
                            + ")\n";
                }
            }
        }
        dataCell = new PdfPCell(new Phrase("\n" + deviceNameWithIP + "\n"));
        dataCell.setBackgroundColor(tableContentBackColor);
        dataCell.setBorderColor(tableBorderColor);
        frontPageTable.addCell(dataCell);

        /*
         * Adding Table to PDF      
         */
        document.add(frontPageTable);

        /*
         * Adding Charts and Table to PDF 
         */
        document.newPage();
        reportBean = ReportBean.getRecordbyPrimarykey(reportID);
        String query = null;
        if (request == null) {
            query = PrepareQuery.getQuery(reportBean, startDate, endDate, applianceID, null, null, "0", limit,
                    paramMap);
        } else {
            PrepareQuery prepareQuery = new PrepareQuery();
            query = prepareQuery.getQuery(reportBean, request);
        }
        String searchQuery = "";
        if (request == null) {
            searchQuery = null;
        } else {
            searchQuery = request.getParameter("searchquery");
        }
        if (searchQuery != null && !"".equalsIgnoreCase(searchQuery)) {
            query = query.replaceFirst("where", "where " + searchQuery + " and");
        }
        CyberoamLogger.sysLog.debug("PDF:ReportID:" + reportBean.getReportId() + "Query->" + query);
        try {
            if (query.indexOf("select") == -1 && query.indexOf("SELECT") == -1) {
                indexManager = new IndexManager();
                rsw = indexManager.getSearch(query);
                //rsw=indexManager.getResutSetFromArrayList(searchRecord);
            } else {
                rsw = sqlReader.getInstanceResultSetWrapper(query);
            }
        } catch (org.postgresql.util.PSQLException e) {
            if (query.indexOf("5min_ts_20") > -1) {
                query = query.substring(0, query.indexOf("5min_ts_20")) + "4hr"
                        + query.substring(query.indexOf("5min_ts_20") + 16, query.length());
                CyberoamLogger.appLog.debug("New query : " + query);
                rsw = sqlReader.getInstanceResultSetWrapper(query);
            } else {
                CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e);
            }
        } catch (Exception e) {
            CyberoamLogger.appLog.error("Exeption in AjaxController.java " + e, e);
            rsw.close();
        }
        /*
         * PDF Rendering work starts here
         */
        //if(Integer.parseInt(limit)<=10 && query.indexOf("where")>-1){
        if (reportBean.getReportFormatId() != 2) {
            chart = Chart.getChart(reportBean.getReportId(), rsw, null);
            PdfTemplate pdfTemplate = contentByte.createTemplate(width, height);
            Graphics2D graphics2D = pdfTemplate.createGraphics(width, height);
            Rectangle2D rectangle = new Rectangle2D.Double(100, 85, 540, rec_hieght);
            chart.draw(graphics2D, rectangle);
            graphics2D.dispose();
            contentByte.addTemplate(pdfTemplate, 0, 0);

            for (int j = 0; j < (int) (rec_hieght / 16) + 1; j++) {
                document.add(new Paragraph("\n"));
            }
        } else
            document.add(new Paragraph("\n"));

        // Retrieving PdfPTable
        PdfPTable pdfTable = getPdfPTable(reportBean, rsw);
        rsw.close();

        document.add(pdfTable);
        CyberoamLogger.appLog.info("*************Finishing PDF Work****************");
    } catch (Exception e) {

        CyberoamLogger.sysLog.debug("Chart.writeChartToPDF.e" + e.getMessage(), e);
    } finally {
        sqlReader.close();
    }
    document.close();
}

From source file:org.cyberoam.iview.charts.Chart.java

License:Open Source License

/**
 * This Event handler Method adds Header and Footer in PDF File
 *//*from  ww  w  . ja va  2  s  .  c o  m*/
public void onEndPage(PdfWriter writer, Document document) {
    try {
        if (document.getPageNumber() > 1) {
            String seperator = System.getProperty("file.separator");
            //String path=System.getProperty("catalina.home") +seperator+"webapps" +seperator+"ROOT" + seperator + "images" + seperator;
            String path = InitServlet.contextPath + seperator + "images" + seperator;
            Image imgHead = Image.getInstance(path + "iViewPDFHeader.JPG");
            Image imgFoot = Image.getInstance(path + "iViewPDFFooter.JPG");
            Rectangle page = document.getPageSize();

            PdfPTable head = new PdfPTable(1);
            head.addCell(imgHead);
            head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin() - 10,
                    page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

            PdfPTable foot = new PdfPTable(1);
            foot.addCell(imgFoot);
            foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
            foot.writeSelectedRows(0, -1, document.leftMargin() - 10, document.bottomMargin() + 24,
                    writer.getDirectContent());
        }
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}