Example usage for com.lowagie.text.pdf PdfPTable setLockedWidth

List of usage examples for com.lowagie.text.pdf PdfPTable setLockedWidth

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable setLockedWidth.

Prototype

public void setLockedWidth(boolean lockedWidth) 

Source Link

Document

Uses the value in setTotalWidth() in Document.add().

Usage

From source file:gov.medicaid.services.impl.ExportServiceBean.java

License:Apache License

/**
 * Sets the given table to take an entire page with.
 * //from   ww  w . j ava 2s .  co  m
 * @param table
 *            the table to make full width
 */
private static void setTableAsFullPage(PdfPTable table) {
    table.getDefaultCell().setBorder(0);
    table.setTotalWidth(72 * 7);
    table.setLockedWidth(true);
}

From source file:gov.medicaid.services.impl.ExportServiceBean.java

License:Apache License

/**
 * Exports the search results into PDF./*  w ww. j  a v a2  s  . co m*/
 * 
 * @param requests
 *            the list to be exported
 * @param status
 *            the status filter
 * @param outputStream
 *            the stream to export to
 * @throws PortalServiceException
 *             for any errors encountered
 */
public void export(List<UserRequest> requests, String status, OutputStream outputStream)
        throws PortalServiceException {
    PdfPTable resultTable;
    try {
        Document document = new Document();
        PdfWriter.getInstance(document, outputStream);
        document.open();

        resultTable = new PdfPTable(new float[] { 3, 8, 8, 8, 10, 25, 8, 8, 8 });
        resultTable.getDefaultCell().setBorder(0);
        resultTable.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

        resultTable.setTotalWidth(72 * 7);
        resultTable.setLockedWidth(true);

        resultTable.addCell(createHeaderCell("Enrollments", 9));
        resultTable.completeRow();

        addCenterCell(resultTable, "#");
        addCenterCell(resultTable, "NPI/UMPI");
        addCenterCell(resultTable, "Date Created");
        addCenterCell(resultTable, "Request Type");
        addCenterCell(resultTable, "Provider Type");
        addCenterCell(resultTable, "Provider Name");
        addCenterCell(resultTable, "Risk Level");
        addCenterCell(resultTable, "Status");
        addCenterCell(resultTable, "Status Date");
        resultTable.completeRow();

        int i = 0;
        for (UserRequest userRequest : requests) {
            addCenterCell(resultTable, String.valueOf(++i));
            addCenterCell(resultTable, userRequest.getNpi());
            addCenterCell(resultTable,
                    BinderUtils.formatCalendar(BinderUtils.toCalendar(userRequest.getCreateDate())));
            addCenterCell(resultTable, userRequest.getRequestType());
            addCenterCell(resultTable, userRequest.getProviderType());
            addCenterCell(resultTable, userRequest.getProviderName());
            addCenterCell(resultTable, userRequest.getRiskLevel());
            addCenterCell(resultTable, userRequest.getStatus());
            addCenterCell(resultTable,
                    BinderUtils.formatCalendar(BinderUtils.toCalendar(userRequest.getStatusDate())));
        }

        resultTable.setSpacingAfter(20);
        document.add(resultTable);

        document.close();
    } catch (DocumentException e) {
        throw new PortalServiceException("Export failed, see log for additional details.", e);
    }
}

From source file:gov.medicaid.services.util.PDFHelper.java

License:Apache License

/**
 * Sets the given table to take an entire page with.
 *
 * @param table the table to make full width
 *//*www  .j av a 2  s  .  c  o  m*/
public static void setTableAsFullPage(PdfPTable table) {
    table.getDefaultCell().setBorder(0);
    table.setTotalWidth(72 * 7);
    table.setLockedWidth(true);
}

From source file:it.eng.spagobi.engines.documentcomposition.exporterUtils.PdfCreator.java

License:Mozilla Public License

public FileOutputStream createPdfFile(FileOutputStream fileOutputStream,
        Map<String, DocumentContainer> documentsMap, boolean defaultStyle)
        throws MalformedURLException, IOException, DocumentException {

    logger.debug("IN");

    Document document = new Document(PageSize.A4.rotate());
    Rectangle rect = document.getPageSize();
    docWidth = rect.getWidth();/*from  w ww. j  a va 2  s .co m*/
    docHeight = rect.getHeight();

    logger.debug("document size width: " + docWidth + " height: " + docHeight);

    //PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("C:/comp/SpagoBIProva.pdf"));
    PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);
    document.open();

    int documentsNumber = documentsMap.keySet().size();
    int columnnsNumber = 2;

    if (defaultStyle == true) {
        logger.debug("use default style");
        int cellsCounter = 0;

        PdfPTable table = new PdfPTable(columnnsNumber);
        table.setWidthPercentage(100);

        for (Iterator iterator = documentsMap.keySet().iterator(); iterator.hasNext();) {
            String label = (String) iterator.next();
            DocumentContainer docContainer = documentsMap.get(label);
            byte[] content = docContainer.getContent();
            if (content != null) {
                Image img = null;
                try {
                    img = Image.getInstance(content);
                    table.addCell(img);
                } catch (Exception e) {
                    logger.debug("Trying to evaluate response as a PDF file... ");
                    table.addCell("");
                    //                  try {
                    //                     PdfReader reader = new PdfReader(content);
                    //                     PdfImportedPage page = writer.getImportedPage(reader, 1);
                    //                     writer.addPage(page);
                    //                     table.addCell("");
                    //                  } catch (Exception x) {
                    //                     logger.error("Error in inserting image for document " + label, e);
                    //                     logger.error("Error in inserting pdf file for document " + label, x);
                    //                     table.addCell("");
                    //                  }
                }
            }
            cellsCounter++;
        }

        // if cell counter is not pair make it pair
        if (cellsCounter % 2 != 0) {
            table.addCell("");
        }
        document.add(table);

    } else { // ************* NO DEFAULT STYLE *****************
        logger.debug("No default style");

        // I want to calculate total height of scaled heights!!
        //int totalScaledHeight=calculateTotaleScaledHeights(documentsMap, defaultStyle);

        // run on all documents
        for (Iterator iterator = documentsMap.keySet().iterator(); iterator.hasNext();) {
            String label = (String) iterator.next();
            logger.debug("document with label " + label);

            DocumentContainer docContainer = documentsMap.get(label);
            MetadataStyle style = docContainer.getStyle();

            // one table for each image, set at absolute position
            PdfPTable table = new PdfPTable(1);

            // width and height specified for the container by style attribute
            int widthStyle = style.getWidth();
            int heightStyle = style.getHeight();
            logger.debug("style for document width: " + widthStyle + " height: " + heightStyle);

            // width and height for the table scaled to the document size
            int tableWidth = calculatePxSize(docWidth, widthStyle, videoWidth);
            int tableHeight = calculatePxSize(docHeight, heightStyle, videoHeight);

            logger.debug("table for document width: " + tableWidth + " height: " + tableHeight);

            // x and y position as specified for the container by the style attribute
            int yStyle = style.getY();
            int xStyle = style.getX();
            // width and height scaled to the document size
            int xPos = (calculatePxPos(docWidth, xStyle, videoWidth));
            int yPos = (int) docHeight - (calculatePxPos(docHeight, yStyle, videoHeight));
            logger.debug("Table position at x: " + xPos + " y: " + yPos);

            // get the image
            byte[] content = docContainer.getContent();
            if (content != null) {
                Image img = null;
                try {
                    img = Image.getInstance(content);
                } catch (Exception e) {
                    logger.debug("Trying to evaluate response as a PDF file... ");
                    try {
                        PdfReader reader = new PdfReader(content);
                        PdfContentByte cb = writer.getDirectContent();
                        PdfImportedPage page = writer.getImportedPage(reader, 1);
                        float[] tm = getTransformationMatrix(page, xPos, yPos, tableWidth, tableHeight);
                        cb.addTemplate(page, tm[0], tm[1], tm[2], tm[3], tm[4], tm[5]);
                    } catch (Exception x) {
                        logger.error("Error in inserting image for document " + label, e);
                        logger.error("Error in inserting pdf file for document " + label, x);
                    }
                    continue;
                }

                //if it is a REPORT and has more than one page, too large, you have to resize the image, but how to understand it?
                // if image size is more than double of the container size cut the first part,otherwise scale it
                if (docContainer.getDocumentType().equals("REPORT")) {
                    boolean cutImageWIdth = isToCutWidth(img, tableWidth);
                    boolean cutImageHeight = isToCutHeight(img, tableWidth);

                    if (cutImageWIdth == true || cutImageHeight == true) {
                        logger.debug(
                                "Report will be cut to width " + tableWidth + " and height " + tableHeight);
                        try {
                            img = cutImage(content, cutImageHeight, cutImageWIdth, tableHeight, tableWidth,
                                    (int) img.getWidth(), (int) img.getHeight());
                        } catch (Exception e) {
                            logger.error(
                                    "Error in image cut, cutt will be ignored and image will be drawn anyway ",
                                    e);
                        }
                    }
                }

                // this is percentage to resize
                // The image must be size within the cell               
                int percToResize = percentageToResize((int) img.getWidth(), (int) img.getHeight(), tableWidth,
                        tableHeight);
                logger.debug("image will be scaled of percentage " + percToResize);
                img.scalePercent(percToResize);

                PdfPCell cell = new PdfPCell(img);
                cell.setNoWrap(true);
                cell.setFixedHeight(tableHeight);
                cell.setBorderWidth(0);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setVerticalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);

                //table.setWidthPercentage(tableWidthPerc);
                table.setTotalWidth(tableWidth);
                table.setLockedWidth(true);
            } else {
                // TODO: setALT!
            }
            logger.debug("Add table");
            table.writeSelectedRows(0, -1, xPos, yPos, writer.getDirectContent());
            logger.debug("Document added");
        }

    }
    document.close();
    logger.debug("OUT");
    return fileOutputStream;
}

From source file:net.nosleep.superanalyzer.Share.java

License:Open Source License

public static void saveAnalysisPdf(JFrame window, Analysis analysis, JProgressBar progressBar) {

    File pdfFile = askForFile(window, "pdf");
    if (pdfFile == null)
        return;// w ww .jav a  2  s.com

    Misc.printMemoryInfo("pdfstart");

    DateFormat dateFormat = new SimpleDateFormat().getDateInstance(DateFormat.SHORT);
    String infoString = Misc.getString("CREATED_ON") + " "
            + dateFormat.format(Calendar.getInstance().getTime());

    int viewCount = 15;
    int viewsDone = 0;

    progressBar.setMinimum(0);
    progressBar.setMaximum(viewCount);

    Dimension d = new Dimension(500, 400);

    try {

        String tmpPath = System.getProperty("java.io.tmpdir") + "/image.png";

        // create the pdf document object
        Document document = new Document();

        // create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter.getInstance(document, new FileOutputStream(pdfFile));

        // we open the document
        document.open();

        Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.NORMAL,
                new Color(0x00, 0x00, 0x00));

        Paragraph p = new Paragraph(Misc.getString("MY_MUSIC_COLLECTION"), titleFont);
        p.setSpacingAfter(4);
        document.add(p);

        Font subtitleFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,
                new Color(0x88, 0x88, 0x88));

        p = new Paragraph("The Super Analyzer by Nosleep Software", subtitleFont);
        p.setSpacingAfter(-2);
        document.add(p);

        p = new Paragraph(infoString, subtitleFont);
        p.setSpacingAfter(30);
        document.add(p);

        PdfPTable table = new PdfPTable(2);
        table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        table.setTotalWidth(500f);
        table.setLockedWidth(true);

        Font statNameFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,
                new Color(0x66, 0x66, 0x66));

        Font statValueFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,
                new Color(0x00, 0x00, 0x00));

        Vector<StringTriple> statPairs = SummaryView.createStatPairs(analysis);
        Paragraph statParagraph = new Paragraph();

        Font summaryTitleFont = FontFactory.getFont(FontFactory.HELVETICA, 11, Font.BOLD,
                new Color(0x00, 0x00, 0x00));
        Paragraph titleParagraph = new Paragraph(Misc.getString("SUMMARY"), summaryTitleFont);
        statParagraph.add(titleParagraph);

        Paragraph spaceParagraph = new Paragraph("", statNameFont);
        statParagraph.add(spaceParagraph);

        for (int i = 0; i < statPairs.size(); i++) {
            Paragraph statLine = new Paragraph();
            StringTriple triple = statPairs.elementAt(i);
            Phrase namePhrase = new Phrase(triple.Name + ": ", statNameFont);
            Phrase valuePhrase = new Phrase(triple.Value, statValueFont);
            statLine.add(namePhrase);
            statLine.add(valuePhrase);
            statParagraph.add(statLine);
        }
        table.addCell(statParagraph);

        viewsDone++;
        progressBar.setValue(viewsDone);

        GenreView genreView = new GenreView(analysis);
        genreView.saveImage(new File(tmpPath), d);
        genreView = null;

        Image img = Image.getInstance(tmpPath);
        table.addCell(img);

        viewsDone++;
        progressBar.setValue(viewsDone);

        LikesView likesView = new LikesView(analysis);
        likesView.saveImage(new File(tmpPath), d);
        likesView = null;

        img = Image.getInstance(tmpPath);
        table.addCell(img);

        viewsDone++;
        progressBar.setValue(viewsDone);

        YearView yearView = new YearView(analysis);
        yearView.saveImage(new File(tmpPath), d);
        yearView = null;

        img = Image.getInstance(tmpPath);
        table.addCell(img);

        viewsDone++;
        progressBar.setValue(viewsDone);

        RatingView ratingView = new RatingView(analysis);
        ratingView.saveImage(new File(tmpPath), d);
        ratingView = null;

        img = Image.getInstance(tmpPath);
        table.addCell(img);

        viewsDone++;
        progressBar.setValue(viewsDone);

        TimeView timeView = new TimeView(analysis);
        timeView.saveImage(new File(tmpPath), d);
        timeView = null;

        img = Image.getInstance(tmpPath);
        table.addCell(img);

        viewsDone++;
        progressBar.setValue(viewsDone);

        QualityView qualityView = new QualityView(analysis);
        qualityView.saveImage(new File(tmpPath), d);
        qualityView = null;

        img = Image.getInstance(tmpPath);
        table.addCell(img);

        viewsDone++;
        progressBar.setValue(viewsDone);

        PlayCountView playCountView = new PlayCountView(analysis);
        playCountView.saveImage(new File(tmpPath), d);
        playCountView = null;

        img = Image.getInstance(tmpPath);
        table.addCell(img);

        viewsDone++;
        progressBar.setValue(viewsDone);

        MostPlayedAAView mostPlayedAAView = new MostPlayedAAView(analysis);

        mostPlayedAAView.saveImage(new File(tmpPath), d);
        img = Image.getInstance(tmpPath);
        table.addCell(img);

        mostPlayedAAView.saveImageExtra(new File(tmpPath), d);
        img = Image.getInstance(tmpPath);
        table.addCell(img);

        mostPlayedAAView = null;

        viewsDone++;
        progressBar.setValue(viewsDone);

        MostPlayedDGView mostPlayedDGView = new MostPlayedDGView(analysis);

        mostPlayedDGView.saveImage(new File(tmpPath), d);
        img = Image.getInstance(tmpPath);
        table.addCell(img);

        mostPlayedDGView.saveImageExtra(new File(tmpPath), d);
        img = Image.getInstance(tmpPath);
        table.addCell(img);

        mostPlayedDGView = null;

        viewsDone++;
        progressBar.setValue(viewsDone);

        EncodingKindView encodingKindView = new EncodingKindView(analysis);
        encodingKindView.saveImage(new File(tmpPath), d);
        encodingKindView = null;

        img = Image.getInstance(tmpPath);
        table.addCell(img);

        viewsDone++;
        progressBar.setValue(viewsDone);

        GrowthView growthView = new GrowthView(analysis);
        growthView.saveImage(new File(tmpPath), d);
        growthView = null;

        img = Image.getInstance(tmpPath);
        table.addCell(img);

        viewsDone++;
        progressBar.setValue(viewsDone);

        WordView wordView = new WordView(analysis);
        wordView.saveImage(new File(tmpPath), d);
        wordView = null;

        img = Image.getInstance(tmpPath);
        table.addCell(img);

        table.addCell("");

        viewsDone++;
        progressBar.setValue(viewsDone);
        Misc.printMemoryInfo("pdfend");

        document.add(table);

        // step 5: we close the document
        document.close();

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
}

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

License:Open Source License

/**
 * This method is used for add the main information table of project summary
 *///from   w ww  .j  a va2s .c o m
private void addMainInformationTable() {

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

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

    Paragraph cellContent;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

License:Open Source License

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

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

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

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

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

        Anchor anchor;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    }
                }

                document.newPage();
            }
        }

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

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

License:Open Source License

/**
 * This method add Activities for the summary project
 *//* w  w  w  .j  av  a 2  s.  co m*/
private void addActivities() {

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

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

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

                        }

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

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

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

                        this.addTableHeaderCell(table, cell_new);

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

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

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

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

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

                        }
                        try {

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

                        }

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

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

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

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

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

                        PartnerPerson activityPartnerPerson = activity.getLeader();

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

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

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

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

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

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

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

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

                    }
                }

            }

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

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

        }

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

}

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

License:Open Source License

private void addBudgetReporting(String number) {

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

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

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

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

                    this.addTableHeaderCellColspan(table, leverageBlock, 2);

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

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

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

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

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

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

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

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

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

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

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

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

}

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

License:Open Source License

/**
 * This Method is for to calculate the overall or gender summary
 * //from   w  w  w.  j av  a  2s .c o m
 * @param startYear start year to calculate the summary
 * @param endYear end year to calculate the summary
 * @param type this is used for to determinate the type the report to create
 */
private void addBudgetsSummaryByPartners(int startYear, int endYear, int typeSummary) {

    try {
        Paragraph cell;
        if (typeSummary == 0) {
            cell = new Paragraph(this.getText("summaries.project.budget.summary", new String[] { "Overall" }),
                    BODY_TEXT_BOLD_FONT);
        } else {
            cell = new Paragraph(this.getText("summaries.project.budget.summary", new String[] { "Gender" }),
                    BODY_TEXT_BOLD_FONT);
        }
        PdfPTable table;
        if (project.isCoFundedProject()) {
            table = new PdfPTable(4);
            table.setWidths(new int[] { 2, 3, 3, 3 });
        } else {
            table = new PdfPTable(2);
            table.setWidths(new int[] { 3, 3 });
        }

        table.setLockedWidth(true);
        table.setTotalWidth(400);

        table.setHeaderRows(1);

        // Add cell with the name summary
        this.addCustomTableCell(table, cell, Element.ALIGN_CENTER, BODY_TEXT_BOLD_FONT, Color.WHITE,
                table.getNumberOfColumns(), 0, false);

        cell = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT);
        this.addTableHeaderCell(table, cell);

        if (project.isCoFundedProject()) {

            if (typeSummary == 0) {
                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.text",
                                new String[] { BudgetType.W1_W2.name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
                this.addTableHeaderCell(table, cell);

                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.text",
                                new String[] { BudgetType.W3_BILATERAL.name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
            } else {
                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.gender",
                                new String[] { BudgetType.W1_W2.name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
                this.addTableHeaderCell(table, cell);

                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.gender",
                                new String[] { BudgetType.W3_BILATERAL.name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
            }
            this.addTableHeaderCell(table, cell);

            // Total column
            cell = new Paragraph(this.getText("summaries.project.budget.overall.total") + " (USD)",
                    TABLE_HEADER_FONT);
            this.addTableHeaderCell(table, cell);
        }

        else {

            if (typeSummary == 0) {
                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.text",
                                new String[] { this.getBudgetType().name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
            } else {
                cell = new Paragraph(
                        this.getText("summaries.project.budget.overall.gender",
                                new String[] { this.getBudgetType().name().replace("_", "/") }) + "(USD)",
                        TABLE_HEADER_FONT);
            }
            this.addTableHeaderCell(table, cell);
        }

        double value, valueSum;
        value = 0.0;

        for (int year = startYear; year <= endYear; year++) {
            cell = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT);
            this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 0);

            valueSum = 0.0;

            if (project.isCoFundedProject()) {
                if (typeSummary == 0) {
                    // amount w1/w2
                    value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(),
                            BudgetType.W1_W2.getValue(), year);
                    cell = new Paragraph(this.budgetFormatter.format(value), TABLE_BODY_FONT);
                    ;
                    this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                    valueSum = value;

                    // amount w3/Bilateral
                    value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(),
                            BudgetType.W3_BILATERAL.getValue(), year);

                } else {

                    // gender w1/w2
                    value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(),
                            BudgetType.W1_W2.getValue(), year);
                    cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT);
                    ;
                    this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                    valueSum = value;

                    // gender w3/Bilateral
                    value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(),
                            BudgetType.W3_BILATERAL.getValue(), year);
                }

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

                // Total
                valueSum += value;
                cell = new Paragraph(budgetFormatter.format(valueSum), TABLE_BODY_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

            } else {
                if (typeSummary == 0) {
                    // amount w1/w2
                    value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(),
                            this.getBudgetType().getValue(), year);
                    cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT);
                    ;
                    this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

                } else {

                    // gender w1/w2
                    value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(),
                            this.getBudgetType().getValue(), year);
                    cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT);
                    ;
                    this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);

                }
            }
        }

        // ********************** Totals *************

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

        if (project.isCoFundedProject()) {

            if (typeSummary == 0) {
                value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(),
                        BudgetType.W1_W2.getValue());
                cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                valueSum = value;

                value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(),
                        BudgetType.W3_BILATERAL.getValue());
                cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                valueSum += value;
            } else {

                value = budgetManager.calculateTotalGenderPercentageByType(project.getId(),
                        BudgetType.W1_W2.getValue());
                cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                valueSum = value;

                value = budgetManager.calculateTotalGenderPercentageByType(project.getId(),
                        BudgetType.W3_BILATERAL.getValue());
                cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
                this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
                valueSum += value;
            }

            // Total
            cell = new Paragraph(budgetFormatter.format(valueSum), TABLE_BODY_BOLD_FONT);
            this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
        }

        else {
            if (typeSummary == 0) {
                value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(),
                        this.getBudgetType().getValue());
            } else {
                value = budgetManager.calculateTotalGenderPercentageByType(project.getId(),
                        this.getBudgetType().getValue());
            }

            cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT);
            this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1);
            valueSum = value;
        }
        document.add(table);
        cell = new Paragraph(Chunk.NEWLINE);
        document.add(cell);

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