Example usage for com.lowagie.text Element ALIGN_JUSTIFIED

List of usage examples for com.lowagie.text Element ALIGN_JUSTIFIED

Introduction

In this page you can find the example usage for com.lowagie.text Element ALIGN_JUSTIFIED.

Prototype

int ALIGN_JUSTIFIED

To view the source code for com.lowagie.text Element ALIGN_JUSTIFIED.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

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;/* ww w  .j a v  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

/**
 * This method is used for add Outcomes in the project summary
 *//*from  w  ww . j a  va 2 s .c o  m*/
private void addProjectOutcomes(String number) {
    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 (DocumentException e) {
        LOG.error("There was an error trying to add the project focuses to the project summary pdf", e);
    }

    Anchor anchor;
    currentPlanningYear--;
    ////////////////// Reporting
    PdfPTable table;
    if (project.isReporting()) {
        for (int year = currentPlanningYear; year < midOutcomeYear; year++) {

            // Annual progress towards
            outcomesBlock = new Paragraph();
            outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED);
            outcomesBlock.setFont(BODY_TEXT_BOLD_FONT);
            outcomesBlock.add(this.getText("summaries.project.outcomeAnnualProgress",
                    new String[] { String.valueOf(year) }));
            outcomesBlock.setFont(BODY_TEXT_FONT);

            if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null) {
                outcomesBlock.add(this.getText("summaries.project.empty"));
            } else {
                outcomesBlock.add(
                        this.messageReturn(project.getOutcomes().get(String.valueOf(year)).getStatement()));
            }
            outcomesBlock.add(Chunk.NEWLINE);
            outcomesBlock.add(Chunk.NEWLINE);

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

            if (year == this.currentPlanningYear) {
                table = new PdfPTable(1);
                table.setLockedWidth(true);
                table.setTotalWidth(500);

                ///// outcome toward in reporting cycle
                outcomesBlock = new Paragraph();
                outcomesBlock.setFont(TABLE_BODY_BOLD_FONT);
                outcomesBlock.add(this.getText("summaries.project.outcomeAnnualTowards",
                        new String[] { String.valueOf(year) }));

                outcomesBlock.setFont(TABLE_BODY_FONT);

                if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null) {
                    outcomesBlock.add(this.getText("summaries.project.empty"));
                } else {
                    outcomesBlock.add(this
                            .messageReturn(project.getOutcomes().get(String.valueOf(year)).getAnualProgress()));
                }

                this.addTableBodyCell(table, outcomesBlock, Element.ALIGN_JUSTIFIED, 1);

                ///// outcome communication
                outcomesBlock = new Paragraph();
                outcomesBlock.setFont(TABLE_BODY_BOLD_FONT);
                outcomesBlock.add(this.getText("summaries.project.outcomeAnnualCommunication"));
                outcomesBlock.setFont(TABLE_BODY_FONT);

                if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null) {
                    outcomesBlock.add(this.getText("summaries.project.empty"));
                } else {
                    outcomesBlock.add(this
                            .messageReturn(project.getOutcomes().get(String.valueOf(year)).getComunication()));
                }
                this.addTableBodyCell(table, outcomesBlock, Element.ALIGN_JUSTIFIED, 1);

                // Any evendence
                outcomesBlock = new Paragraph();
                outcomesBlock.setFont(TABLE_BODY_BOLD_FONT);
                outcomesBlock.add(this.getText("summaries.project.outcomeAnnualEvidence"));
                outcomesBlock.setFont(TABLE_BODY_FONT);

                if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null
                        || project.getOutcomes().get(String.valueOf(year)).getFile() == null
                        || project.getOutcomes().get(String.valueOf(year)).getFile().equals("")) {
                    outcomesBlock.add(this.getText("summaries.project.empty"));
                } else {

                    anchor = new Anchor(project.getOutcomes().get(String.valueOf(year)).getFile(),
                            TABLE_BODY_FONT_LINK);
                    anchor.setReference(config.getDownloadURL() + "/projects/" + project.getId()
                            + "/project_outcome/" + project.getOutcomes().get(String.valueOf(year)).getFile());
                    outcomesBlock.add(anchor);
                }
                this.addTableBodyCell(table, outcomesBlock, Element.ALIGN_LEFT, 1);
                try {
                    document.add(table);
                    outcomesBlock = new Paragraph();
                    outcomesBlock.add(Chunk.NEWLINE);
                    document.add(outcomesBlock);
                } catch (DocumentException e) {
                    LOG.error("There was an error trying to add the project focuses to the project summary pdf",
                            e);
                }
            }
        }

    }
    ////////////////// Planning
    else {
        String outcomeProgress = new String();
        for (int year = currentPlanningYear; year < midOutcomeYear; year++) {
            // Annual progress towards
            outcomesBlock = new Paragraph();
            outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED);
            outcomesBlock.setFont(BODY_TEXT_BOLD_FONT);
            outcomesBlock.add(this.getText("summaries.project.outcomeAnnualProgress",
                    new String[] { String.valueOf(year) }));

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

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

    }

    // Lesson regardins
    outcomesBlock = new Paragraph();
    outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED);
    outcomesBlock.setFont(BODY_TEXT_BOLD_FONT);
    if (project.isReporting()) {
        outcomesBlock.add(this.getText("summaries.project.outcome.reporting.lessonRegarding"));
    } else {
        outcomesBlock.add(this.getText("summaries.project.outcome.lessonRegarding"));
    }
    outcomesBlock.setFont(BODY_TEXT_FONT);
    if (project.getComponentLesson("outcomes") != null) {
        outcomesBlock.add(this.messageReturn(project.getComponentLesson("outcomes").getLessons()));
    } else {
        outcomesBlock.add(this.messageReturn(null));
    }
    try {
        document.add(outcomesBlock);
    } catch (DocumentException e) {
        LOG.error("There was an error trying to add the project focuses to the project summary pdf", e);
    }
    // ******************* CCAFS Outcomes***************/
    this.addProjectCCAFSOutcomes(number);

    // **********************************************************************************
    // ******************* Other contributions***************/
    // **********************************************************************************

    OtherContribution otherContribution = project.getIpOtherContribution();

    try {
        outcomesBlock = new Paragraph();
        outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED);

        title = new Paragraph(
                number + ".3 " + this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions"),
                HEADING3_FONT);
        outcomesBlock.add(Chunk.NEWLINE);
        outcomesBlock.add(Chunk.NEWLINE);
        outcomesBlock.add(title);
        outcomesBlock.add(Chunk.NEWLINE);

        // Contribution to other Impact Pathways:
        outcomesBlock.setFont(BODY_TEXT_BOLD_FONT);
        if (project.isReporting()) {
            outcomesBlock.add(this.getText(
                    "summaries.project.outcome.ccafs.outcomes.reporting.other.contributions.pathways"));
        } else {

            outcomesBlock
                    .add(this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions.pathways"));
        }
        outcomesBlock.setFont(BODY_TEXT_FONT);

        if (otherContribution == null || otherContribution.getContribution() == null
                || otherContribution.getContribution().equals("")) {
            outcomesBlock.add(": " + this.getText("summaries.project.empty"));
        } else {
            outcomesBlock.add(Chunk.NEWLINE);
            outcomesBlock.add(otherContribution.getContribution());
        }

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

        document.add(outcomesBlock);
        document.add(Chunk.NEWLINE);

        Paragraph cell;

        if (project.isReporting()) {

            if (project.getOtherContributions().isEmpty()) {

            } else {
                table = new PdfPTable(4);
                table.setWidths(new int[] { 2, 4, 4, 4 });
                table.setLockedWidth(true);
                table.setTotalWidth(500);

                // adding headers
                cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.region"),
                        TABLE_HEADER_FONT);
                this.addTableHeaderCell(table, cell);

                cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.indicator"),
                        TABLE_HEADER_FONT);
                this.addTableHeaderCell(table, cell);

                cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.describe",
                        new String[] { String.valueOf(this.currentReportingYear) }), TABLE_HEADER_FONT);
                this.addTableHeaderCell(table, cell);

                cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.ablequantily"),
                        TABLE_HEADER_FONT);
                this.addTableHeaderCell(table, cell);

                // Adding contain
                for (ProjecteOtherContributions projectOther : project.getOtherContributions()) {
                    cell = new Paragraph(projectOther.getRegion(), TABLE_BODY_FONT);
                    this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1);

                    cell = new Paragraph(projectOther.getIndicators(), TABLE_BODY_FONT);
                    this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1);

                    cell = new Paragraph(projectOther.getDescription(), TABLE_BODY_FONT);
                    this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1);

                    cell = new Paragraph(String.valueOf(projectOther.getTarget()), TABLE_BODY_FONT);
                    this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1);

                }
                document.add(table);
                document.add(Chunk.NEWLINE);
            }
            // // Collaboration with other CRPs
            cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.collaborating"),
                    BODY_TEXT_BOLD_FONT);

            if (project.getListCRPContributions().isEmpty()) {
                cell.add(": ");
                cell.setFont(BODY_TEXT_FONT);
                cell.add(this.messageReturn(null));
                cell.add(Chunk.NEWLINE);
                document.add(cell);
            } else {
                document.add(cell);
                document.add(Chunk.NEWLINE);

                for (CRPContribution crpContribution : project.getListCRPContributions()) {
                    table = new PdfPTable(1);
                    table.setLockedWidth(true);
                    table.setTotalWidth(500);

                    cell = new Paragraph(this.messageReturn(crpContribution.getCrp().getName()),
                            TABLE_BODY_BOLD_FONT);
                    cell.setAlignment(Element.ALIGN_LEFT);
                    this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1);

                    cell = new Paragraph(
                            this.getText("summaries.project.reporting.ccafs.outcomes.natureCollaboration"),
                            TABLE_BODY_BOLD_FONT);
                    cell.setFont(TABLE_BODY_FONT);
                    cell.add(this.messageReturn(crpContribution.getNatureCollaboration()));
                    this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

                    cell = new Paragraph(
                            this.getText("summaries.project.reporting.ccafs.outcomes.achievedOutcome"),
                            TABLE_BODY_BOLD_FONT);
                    cell.setFont(TABLE_BODY_FONT);
                    cell.add(this.messageReturn(crpContribution.getExplainAchieved()));
                    this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1);

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

            }
        }

        else {
            outcomesBlock = new Paragraph();
            // Contribution to another Center activity:
            outcomesBlock.setFont(BODY_TEXT_BOLD_FONT);
            outcomesBlock
                    .add(this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions.center"));
            outcomesBlock.setFont(BODY_TEXT_FONT);
            if (otherContribution == null || otherContribution.getAdditionalContribution() == null
                    || otherContribution.getAdditionalContribution().equals("")) {
                outcomesBlock.add(": " + this.getText("summaries.project.empty"));
            } else {
                outcomesBlock.add(otherContribution.getAdditionalContribution());
                outcomesBlock.add(Chunk.NEWLINE);
                outcomesBlock.add(Chunk.NEWLINE);

            }

            boolean addParagraph = false;
            cell = new Paragraph();
            ;
            cell.setFont(BODY_TEXT_BOLD_FONT);

            table = new PdfPTable(2);

            cell.add(this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions.covered"));
            if (otherContribution != null)

            {
                List<CRPContribution> listCRP = otherContribution.getCrpContributions();
                if (listCRP.isEmpty()) {
                    cell.setFont(BODY_TEXT_FONT);
                    cell.add(this.getText("summaries.project.empty"));
                    addParagraph = true;
                } else {
                    table.setWidths(new int[] { 4, 6 });
                    table.setLockedWidth(true);
                    table.setTotalWidth(500);

                    this.addCustomTableCell(table, cell, Element.ALIGN_LEFT, BODY_TEXT_FONT, Color.WHITE,
                            table.getNumberOfColumns(), 0, false);

                    // adding headers
                    this.addTableHeaderCell(table,
                            new Paragraph(
                                    this.getText(
                                            "summaries.project.outcome.ccafs.outcomes.other.contributions.crp"),
                                    TABLE_HEADER_FONT));

                    this.addTableHeaderCell(table,
                            new Paragraph(this.getText(
                                    "summaries.project.outcome.ccafs.outcomes.other.contributions.nature"),
                                    TABLE_HEADER_FONT));

                    for (CRPContribution CRPContribution : listCRP) {
                        if (CRPContribution != null && CRPContribution.getCrp() != null) {
                            cell = new Paragraph();
                            cell.setFont(TABLE_BODY_FONT);
                            cell.add(CRPContribution.getCrp().getName());
                            this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1);

                            cell = new Paragraph();
                            cell.setFont(TABLE_BODY_FONT);
                            cell.add(CRPContribution.getNatureCollaboration());
                            this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1);
                        }
                    }
                }
            } else

            {
                cell.add(": ");
                cell.setFont(BODY_TEXT_FONT);
                cell.add(this.getText("summaries.project.empty"));
                addParagraph = true;
            }
            document.add(outcomesBlock);
            // Add paragraphs to document
            if (addParagraph) {
                document.add(cell);
            } else

            {
                document.add(table);
            }

            document.add(Chunk.NEWLINE);

            // Lesson regardins Other contributions
            outcomesBlock = new Paragraph();
            outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED);
            outcomesBlock.setFont(BODY_TEXT_BOLD_FONT);
            outcomesBlock.add(this
                    .getText("summaries.project.outcome.ccafs.outcomes.other.contributions.lessonRegarding"));
            outcomesBlock.setFont(BODY_TEXT_FONT);
            if (project.getComponentLesson("otherContributions") != null)

            {
                outcomesBlock
                        .add(this.messageReturn(project.getComponentLesson("otherContributions").getLessons()));
            } else

            {
                outcomesBlock.add(this.messageReturn(null));
            }
            document.add(outcomesBlock);
        }
        // **********************************************************************************
        // *************************** Outcome Case Studies *************************************
        // **********************************************************************************
        int counter = 0;
        if (project.isReporting()) {
            document.newPage();
            title = new Paragraph(
                    number + ".4 " + this.getText("summaries.project.reporting.outcome.case.studies"),
                    HEADING3_FONT);
            document.add(title);

            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);

                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));
                }
            }
        }

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

}

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

License:Open Source License

/**
 * Entering the project outputs in the summary
 *//*  www .j a va 2 s  .  co m*/
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.ap.summaries.projects.pdf.ProjectSummaryPDF.java

License:Open Source License

/**
 * Entering the project partners in the summary
 *///from  www . j  a v a2 s  .  co m
private void addProjectPartners() {

    Paragraph partnersBlock = new Paragraph();
    partnersBlock.setAlignment(Element.ALIGN_JUSTIFIED);
    partnersBlock.setKeepTogether(true);

    Paragraph title = new Paragraph(32, "2. " + this.getText("summaries.project.projectPartners"),
            HEADING2_FONT);
    partnersBlock.add(title);
    try {
        document.newPage();

        if (project.getLeader() == null && project.getProjectPartners().isEmpty()) {
            title = new Paragraph(this.getText("summaries.project.empty"), BODY_TEXT_FONT);
            partnersBlock.add(title);
            document.add(partnersBlock);
            document.add(Chunk.NEWLINE);
        } else {
            document.add(partnersBlock);
            document.add(Chunk.NEWLINE);

            int c = 1;

            List<ProjectPartner> partnersList = project.getProjectPartners();
            if (!partnersList.isEmpty()) {
                for (ProjectPartner partner : partnersList) {
                    this.addPartner(partner, c);
                    c++;
                }
            }
        }

        if (project.isReporting()) {
            // Please describe how your partnerships overall ha
            List<ProjectPartner> partnersList = project.getProjectPartners();

            partnersBlock = new Paragraph();
            partnersBlock.setAlignment(Element.ALIGN_JUSTIFIED);
            partnersBlock.setFont(BODY_TEXT_BOLD_FONT);
            partnersBlock.add(this.getText("summaries.project.partner.reporting.overall"));
            partnersBlock.setFont(BODY_TEXT_FONT);

            if (!partnersList.isEmpty()) {
                partnersBlock.add(this.messageReturn(partnersList.get(0).getOverall()));
            } else {
                partnersBlock.add(this.messageReturn(null));
            }
            partnersBlock.add(Chunk.NEWLINE);
            partnersBlock.add(Chunk.NEWLINE);
            document.add(partnersBlock);
        }
        // Leason regardins
        partnersBlock = new Paragraph();
        partnersBlock.setAlignment(Element.ALIGN_JUSTIFIED);
        partnersBlock.setFont(BODY_TEXT_BOLD_FONT);
        partnersBlock.add(this.getText("summaries.project.partner.planning.lessonRegarding"));
        partnersBlock.setFont(BODY_TEXT_FONT);
        if (project.getComponentLesson("partners") != null) {
            partnersBlock.add(this.messageReturn(project.getComponentLesson("partners").getLessons()));
        } else {
            partnersBlock.add(this.messageReturn(null));
        }
        document.add(partnersBlock);

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

}

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

License:Open Source License

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

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

License:Open Source License

/**
 * Method used for to add the project summary
 *//*from w w  w.j  ava2 s .  c  o m*/
private void addSummary() {
    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    try {
        Phrase title = new Phrase(this.getText("summaries.project.summary"), BODY_TEXT_BOLD_FONT);
        paragraph.add(title);
        document.add(paragraph);

        paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        Phrase body = new Phrase(this.messageReturn(project.getSummary()), BODY_TEXT_FONT);
        paragraph.add(body);

        document.add(paragraph);

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

From source file:org.freeeed.print.OfficePrint.java

License:Apache License

private void convertCSVToPdf(File officeDocFile, String originalFileName, File outputFile) {
    try {/*  w  ww .  j  a  v a  2s.  c o  m*/
        BufferedReader input = new BufferedReader(new FileReader(officeDocFile));
        Document document = new Document(PageSize.LETTER);
        PdfWriter.getInstance(document, new FileOutputStream(outputFile));
        document.open();
        document.addSubject(originalFileName);
        document.addTitle(originalFileName);

        String line = "";
        while (null != (line = input.readLine())) {
            Paragraph p = new Paragraph(line);
            p.setAlignment(Element.ALIGN_JUSTIFIED);
            document.add(p);
        }
        document.close();
        input.close();

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

From source file:org.gbif.ipt.task.Eml2Rtf.java

License:Apache License

/**
 * Add abstract section. This corresponds to resource's description.
 * //ww w  .j av a  2s.co  m
 * @param doc Document
 * @param eml EML
 * @throws DocumentException if problem occurs during add
 */
private void addAbstract(Document doc, Eml eml) throws DocumentException {
    if (exists(eml.getDescription())) {
        Paragraph p = new Paragraph();
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        p.setFont(font);
        p.add(new Phrase(getText("rtf.abstract"), fontTitle));
        p.add(Chunk.NEWLINE);
        p.add(Chunk.NEWLINE);
        p.add(eml.getDescription().replace("\r\n", "\n"));
        p.add(Chunk.NEWLINE);
        doc.add(p);
        p.clear();
    }
}

From source file:org.gbif.ipt.task.Eml2Rtf.java

License:Apache License

/**
 * Add "Resumen" section. This corresponds to resource's description.
 * /*w w  w.  j  a  va  2  s  .  co  m*/
 * @param doc Document
 * @throws DocumentException if problem occurs during add
 */
private void addRes(Document doc) throws DocumentException {
    if (exists(this.resu)) {
        Paragraph p = new Paragraph();
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        p.setFont(font);
        p.add(new Phrase(getText("rtf.abstract.res"), fontTitle));
        p.add(Chunk.NEWLINE);
        p.add(Chunk.NEWLINE);
        p.add(this.resu);
        p.add(Chunk.NEWLINE);
        doc.add(p);
        p.clear();
    }
}

From source file:org.gbif.ipt.task.Eml2Rtf.java

License:Apache License

/**
 * Add "Abstract" section. This corresponds to resource's description.
 * //  w  ww .jav  a 2 s.  com
 * @param doc Document
 * @throws DocumentException if problem occurs during add
 */
private void addAbs(Document doc) throws DocumentException {
    if (exists(this.abst)) {
        Paragraph p = new Paragraph();
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        p.setFont(font);
        p.add(new Phrase(getText("rtf.abstract.abst"), fontTitle));
        p.add(Chunk.NEWLINE);
        p.add(Chunk.NEWLINE);
        p.add(this.abst);
        p.add(Chunk.NEWLINE);
        doc.add(p);
        p.clear();
    }
}