Example usage for com.lowagie.text Anchor Anchor

List of usage examples for com.lowagie.text Anchor Anchor

Introduction

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

Prototype

public Anchor(float leading, String string) 

Source Link

Document

Constructs an Anchor with a certain leading and a certain String.

Usage

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
 *//*w  w w . j  av a  2s.com*/
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.gbif.ipt.task.Eml2Rtf.java

License:Apache License

/**
 * Add external links section./* www.j  a v  a2  s  .  co  m*/
 * 
 * @param doc Document
 * @param eml EML
 * @throws DocumentException if problem occurs during add
 */
private void addExternalLinks(Document doc, Eml eml) throws DocumentException {
    if (!eml.getPhysicalData().isEmpty()) {
        Paragraph p = new Paragraph();
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        p.setFont(font);

        p.add(new Phrase(getText("rtf.dtasets.external"), fontTitle));
        p.add(Chunk.NEWLINE);
        p.add(Chunk.NEWLINE);
        for (PhysicalData data : eml.getPhysicalData()) {
            p.add(new Phrase(getText("rtf.datasets.description"), fontTitle));
            p.add(Chunk.NEWLINE);
            if (exists(data.getName())) {
                p.add(new Phrase(getText("rtf.datasets.object") + ": ", fontTitle));
                p.add(data.getName());
                p.add(Chunk.NEWLINE);
            }
            if (exists(data.getCharset())) {
                p.add(new Phrase(getText("rtf.datasets.character") + ": ", fontTitle));
                p.add(data.getCharset());
                p.add(Chunk.NEWLINE);
            }
            if (exists(data.getFormat())) {
                p.add(new Phrase(getText("rtf.datasets.format") + ": ", fontTitle));
                p.add(data.getFormat());
                p.add(Chunk.NEWLINE);
            }
            if (exists(data.getFormatVersion())) {
                p.add(new Phrase(getText("rtf.datasets.format.version") + ": ", fontTitle));
                p.add(data.getFormatVersion());
                p.add(Chunk.NEWLINE);
            }
            if (exists(data.getDistributionUrl())) {
                p.add(new Phrase(getText("rtf.datasets.distribution") + ": ", fontTitle));
                Anchor distributionLink = new Anchor(data.getDistributionUrl(), fontLink);
                distributionLink.setReference(data.getDistributionUrl());
                p.add(distributionLink);
                p.add(Chunk.NEWLINE);
            }
            p.add(Chunk.NEWLINE);
        }
        doc.add(p);
        p.clear();
    }
}

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

License:Apache License

/**
 * Construct IPT URL public resource link, and add it to the document. Only public or registered resources can
 * have a public resource link./*from w  w w  .  j a  v  a2s .c  o  m*/
 * </p>
 * e.g. Data published through GBIF: http://localhost:8090/ipt/resource.do?r=shortName
 * 
 * @param doc Document
 * @param resource Resource
 * @throws DocumentException if an error in adding to the document was encountered
 */
private void addResourceLink(Document doc, Resource resource) throws DocumentException {
    if (resource.getStatus() != PublicationStatus.PRIVATE) {
        // begin new paragraph
        Paragraph p = new Paragraph();
        p.setFont(font);

        // construct GBIF link
        p.add(new Phrase(getText("rtf.resourceLink") + " ", fontTitle));
        Anchor gbifLink = new Anchor("GBIF", fontLinkTitle);
        gbifLink.setReference(Constants.GBIF_HOME_PAGE_URL);
        //p.add(gbifLink);
        p.add(": ");

        // attach the IPT Public URL resource link
        URL url = resourceManager.getPublicResourceLink(resource.getShortname());
        String link = (url != null) ? url.toString() : null;
        // the link only gets added, if it isn't null
        if (link != null) {
            Anchor resourceLink = new Anchor(link, fontLink);
            resourceLink.setReference(link);
            p.add(resourceLink);
            p.add(Chunk.NEWLINE);
            doc.add(p);
            p.clear();
        }
    }
}

From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java

License:Open Source License

/**
 * Emits a URL with the specified cover text. Creates a clickable link in the PDF doc.
 * If no cover text is null (so, not specified), then the text defaults to the URL itself.
 * (In other words, http://pz.org would print as is.)
 *
 * @param url the URL of the link/* w w  w.ja v a  2  s.c  om*/
 * @param text words to be printed and made linkable (in lieu of printing the URL)
 */
public void addUrl(final String url, final String text) {
    if (url == null) {
        return;
    }

    String coverText = text;
    if (coverText == null) {
        coverText = url;
    }

    Anchor anchor = new Anchor(coverText, pdfData.getFont().getItextFont());
    anchor.setReference(url);

    try {
        makeSureOutfileIsOpen();
    } catch (IOException ioe) {
        return;
    }

    if (iTPara == null) {
        startNewParagraph();
    }

    iTPara.add(anchor);
}

From source file:org.revager.export.ProtocolPDFExporter.java

License:Open Source License

/**
 * Writes the given meeting to the protocol.
 * //from   w w  w .  j  a  va 2 s  .  com
 * @param meeting
 *            the meeting
 * @param attachExtRefs
 *            true if the external references should be part of the protocol
 * @param showSignatureFields
 *            true, if the signature fields should be part of the protocol
 * 
 * @throws ExportException
 *             If an error occurs while writing the meeting
 */
protected void writeMeeting(Meeting meeting, boolean attachExtRefs, boolean showSignatureFields)
        throws ExportException {
    Protocol protocol = meeting.getProtocol();

    if (protocol != null) {
        try {
            Font plainFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

            Font boldFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

            Font italicFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10);

            Font boldItalicFont = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED),
                    10);

            Font boldFontTitle = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 17);

            Font italicFontTitle = new Font(
                    BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 13);

            /*
             * Base table for the meeting properties
             */
            PdfPTable tableMeeting = new PdfPTable(2);
            tableMeeting.setWidthPercentage(100);
            tableMeeting.setSplitRows(false);
            tableMeeting.getDefaultCell().setBorderWidth(0);
            tableMeeting.getDefaultCell().setPadding(0);

            /*
             * Write date, time and location of the meeting
             */
            String meetingDate = sdfDate.format(protocol.getDate().getTime());

            String meetingTime = sdfTime.format(protocol.getStart().getTime()) + " - "
                    + sdfTime.format(protocol.getEnd().getTime()) + " ["
                    + protocol.getEnd().getTimeZone().getDisplayName() + "]";

            Anchor anchorTitle = new Anchor(translate("Review Meeting on") + " " + meetingDate, boldFontTitle);
            anchorTitle.setName(Long
                    .toString(protocol.getDate().getTimeInMillis() + protocol.getStart().getTimeInMillis()));

            PdfPCell cellTitle = new PdfPCell(anchorTitle);
            cellTitle.setColspan(2);
            cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellTitle.setPadding(0);
            cellTitle.setBorderWidth(0);
            cellTitle.setPaddingTop(PDFTools.cmToPt(0.6f));
            cellTitle.setPaddingBottom(padding * 2);

            tableMeeting.addCell(cellTitle);

            PdfPCell cellTime = new PdfPCell(new Phrase(meetingTime, italicFontTitle));
            cellTime.setColspan(2);
            cellTime.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellTime.setPadding(0);
            cellTime.setBorderWidth(0);
            cellTime.setPaddingBottom(padding * 2);

            tableMeeting.addCell(cellTime);

            String location = protocol.getLocation();

            if (location.trim().equals("")) {
                location = "--";
            }

            PdfPCell cellLocation = new PdfPCell(
                    new Phrase(translate("Location") + ": " + location, italicFontTitle));
            cellLocation.setColspan(2);
            cellLocation.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellLocation.setPadding(0);
            cellLocation.setBorderWidth(0);
            cellLocation.setPaddingBottom(PDFTools.cmToPt(1.5f));

            tableMeeting.addCell(cellLocation);

            /*
             * Compare with planned meeting
             */
            PdfPCell cellPlanned;

            boolean plannedDateEqualsProtocolDate = meeting.getPlannedDate()
                    .get(Calendar.DAY_OF_MONTH) == protocol.getDate().get(Calendar.DAY_OF_MONTH)
                    && meeting.getPlannedDate().get(Calendar.MONTH) == protocol.getDate().get(Calendar.MONTH)
                    && meeting.getPlannedDate().get(Calendar.YEAR) == protocol.getDate().get(Calendar.YEAR);
            boolean plannedStartEqualsProtocolStart = meeting.getPlannedStart().get(Calendar.HOUR) == protocol
                    .getStart().get(Calendar.HOUR)
                    && meeting.getPlannedStart().get(Calendar.MINUTE) == protocol.getStart()
                            .get(Calendar.MINUTE)
                    && meeting.getPlannedStart().get(Calendar.AM_PM) == protocol.getStart().get(Calendar.AM_PM);
            boolean plannedEndEqualsProtocolEnd = meeting.getPlannedEnd().get(Calendar.HOUR) == protocol
                    .getEnd().get(Calendar.HOUR)
                    && meeting.getPlannedEnd().get(Calendar.MINUTE) == protocol.getEnd().get(Calendar.MINUTE)
                    && meeting.getPlannedEnd().get(Calendar.AM_PM) == protocol.getEnd().get(Calendar.AM_PM);
            boolean plannedLocationEqualsProtocolLocation = meeting.getPlannedLocation()
                    .equals(protocol.getLocation());

            if (plannedDateEqualsProtocolDate && plannedStartEqualsProtocolStart && plannedEndEqualsProtocolEnd
                    && plannedLocationEqualsProtocolLocation) {
                cellPlanned = new PdfPCell(
                        new Phrase(translate("The meeting took place as it has been planned."), plainFont));
            } else {
                cellPlanned = new PdfPCell();

                cellPlanned.addElement(new Phrase(translate(
                        "The meeting didn't take place as it has been planned. The meeting was planned:"),
                        plainFont));

                /*
                 * Planned date, time and location
                 */
                String plannedDate = sdfDate.format(meeting.getPlannedDate().getTime());

                String plannedTime = sdfTime.format(meeting.getPlannedStart().getTime()) + " - "
                        + sdfTime.format(meeting.getPlannedEnd().getTime()) + " ["
                        + meeting.getPlannedEnd().getTimeZone().getDisplayName() + "]";

                Phrase phrasePlanned = new Phrase(plannedDate + " (" + plannedTime + "); "
                        + translate("Location") + ": " + meeting.getPlannedLocation(), italicFont);

                cellPlanned.addElement(phrasePlanned);
            }

            cellPlanned.setColspan(2);
            cellPlanned.setBorderWidth(0);
            cellPlanned.setPadding(padding);
            cellPlanned.setPaddingBottom(PDFTools.cmToPt(1.5f));

            tableMeeting.addCell(cellPlanned);

            /*
             * Comments of the meeting and protocol
             */
            Phrase phraseComments = new Phrase(translate("Comments on the Meeting:"), boldFont);
            PdfPCell cellComments = new PdfPCell(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            phraseComments = new Phrase(translate("Comments on the Findings List:"), boldFont);
            cellComments = new PdfPCell(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            String meetingComments = meeting.getComments();
            if (meetingComments.trim().equals("")) {
                meetingComments = "--";
            }

            phraseComments = new Phrase(meetingComments, italicFont);
            phraseComments.setLeading(leading);
            cellComments = new PdfPCell();
            cellComments.addElement(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setPaddingBottom(padding * 1.8f);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            String protocolComments = protocol.getComments();
            if (protocolComments.trim().equals("")) {
                protocolComments = "--";
            }

            phraseComments = new Phrase(protocolComments, italicFont);
            phraseComments.setLeading(leading);
            cellComments = new PdfPCell();
            cellComments.addElement(phraseComments);
            cellComments.setBorderWidth(0);
            cellComments.setPadding(padding);
            cellComments.setPaddingBottom(padding * 1.8f);
            cellComments.setBorderColor(verticalBorderColor);
            cellComments.setBorderWidthLeft(verticalBorderWidth);

            tableMeeting.addCell(cellComments);

            /*
             * Strut cell
             */
            tableMeeting.addCell(createVerticalStrut(PDFTools.cmToPt(1.3f), 2));

            /*
             * Write attendees
             */
            if (protMgmt.getAttendees(protocol).size() > 0) {
                PdfPCell cellAtt = new PdfPCell(new Phrase(
                        translate("The following attendees participated") + " ("
                                + protMgmt.getAttendees(protocol).size() + " " + translate("attendees") + "):",
                        boldItalicFont));
                cellAtt.setColspan(2);
                cellAtt.setPadding(0);
                cellAtt.setBorderWidth(0);
                cellAtt.setPadding(padding);
                cellAtt.setPaddingBottom(PDFTools.cmToPt(0.8f));

                tableMeeting.addCell(cellAtt);
            }

            pdfDoc.add(tableMeeting);

            if (protMgmt.getAttendees(protocol).size() > 0) {
                writeAttendees(protocol, true, true, showSignatureFields);
            }

            /*
             * If there isn't any finding, finish the export here.
             */
            if (findMgmt.getNumberOfFindings(protocol) == 0) {
                return;
            } else if (findMgmt.getNumberOfFindings(protocol) == 1) {
                Finding find = findMgmt.getFindings(protocol).get(0);

                if (find.getDescription().trim().equals("") && find.getExternalReferences().size() == 0
                        && find.getReferences().size() == 0 && find.getAspects().size() == 0) {
                    return;
                }
            }

            /*
             * Write findings
             */
            pdfDoc.newPage();

            PdfPTable tableFindIntro = new PdfPTable(1);
            tableFindIntro.setWidthPercentage(100);

            Phrase phraseFindIntro = new Phrase(
                    translate("The following findings were recorded by the participating reviewers") + " ("
                            + findMgmt.getNumberOfFindings(protocol) + " " + translate("findings") + "): ",
                    boldItalicFont);
            phraseFindIntro.setLeading(leading);

            PdfPCell cellFindIntro = new PdfPCell();
            cellFindIntro.addElement(phraseFindIntro);
            cellFindIntro.setBorderWidth(0);
            cellFindIntro.setPadding(0);
            cellFindIntro.setPaddingBottom(PDFTools.cmToPt(0.1f));

            tableFindIntro.addCell(cellFindIntro);

            pdfDoc.add(tableFindIntro);

            writeFindings(protocol, attachExtRefs);
        } catch (Exception e) {
            /*
             * Not part of unit testing because this exception is only
             * thrown if an internal error occurs.
             */
            throw new ExportException(translate("Cannot put the selected review meeting in the PDF document."));
        }
    }
}

From source file:org.tpspencer.tal.mvc.document.DocumentWriterImpl.java

License:Apache License

/**
 * Call to start a new chapter//from w  ww.j  a v  a2s  .  c  o  m
 * 
 * @param key The key for the chapter title
 * @param substitutions The substitutions
 */
public void startChapter(String key, String resources, AppElement element) {
    if (resources != null)
        chapterResources = ResourceBundle.getBundle(resources);

    String text = getText(key, element);

    Anchor anchor = new Anchor(text, h1Font);
    anchor.setName(text);

    chapter = new Chapter(new Paragraph(anchor), ++chapterNumber);
}

From source file:ro.nextreports.engine.exporter.RtfExporter.java

License:Apache License

private RtfCell renderRtfCell(BandElement bandElement, Object value, int gridRow, int gridColumn, int rowSpan,
        int colSpan, boolean image) {
    Map<String, Object> style = buildCellStyleMap(bandElement, value, gridRow, gridColumn, colSpan);
    String stringValue;//from   w  ww  .  java 2 s. c o  m

    FontFactoryImp fact = new FontFactoryImp();
    Font fnt;
    if (bandElement != null) {
        String fontName = (String) style.get(StyleFormatConstants.FONT_NAME_KEY);
        int size = ((Float) style.get(StyleFormatConstants.FONT_SIZE)).intValue();
        fnt = getFont(fontName, size);
    } else {
        fnt = getFont(10);
    }

    RtfCell cell = null;
    boolean specialCell = false;
    if (image) {
        try {
            if (value == null) {
                cell = new RtfCell(new Phrase(IMAGE_NOT_FOUND));
            } else {
                ImageBandElement ibe = (ImageBandElement) bandElement;
                byte[] imageBytes = getImage((String) value, ibe.getWidth(), ibe.getHeight());
                cell = new RtfCell(Image.getInstance(imageBytes));
            }
        } catch (Exception e) {
            cell = new RtfCell(IMAGE_NOT_LOADED);
        }
        specialCell = true;
    } else if (bandElement instanceof HyperlinkBandElement) {
        Hyperlink hyperlink = ((HyperlinkBandElement) bandElement).getHyperlink();
        Anchor anchor = new Anchor(hyperlink.getText(), fnt);
        anchor.setReference(hyperlink.getUrl());
        Phrase ph = new Phrase();
        ph.add(anchor);
        try {
            cell = new RtfCell(ph);
        } catch (BadElementException e) {
            e.printStackTrace();
            cell = new RtfCell(hyperlink.getText());
        }
        specialCell = true;
    } else if (bandElement instanceof ReportBandElement) {
        Report report = ((ReportBandElement) bandElement).getReport();
        ExporterBean eb = null;
        try {
            eb = getSubreportExporterBean(report);
            RtfExporter subExporter = new RtfExporter(eb);
            subExporter.export();
            Table innerTable = subExporter.getTable();
            cell = new RtfCell(innerTable);
        } catch (Exception e) {
            cell = new RtfCell();
            e.printStackTrace();
        } finally {
            if ((eb != null) && (eb.getResult() != null)) {
                eb.getResult().close();
            }
        }
        specialCell = true;
    } else if (bandElement instanceof VariableBandElement) {
        VariableBandElement vbe = (VariableBandElement) bandElement;
        Variable var = VariableFactory.getVariable(vbe.getVariable());
        if (var instanceof PageNoVariable) {
            cell = new RtfCell();
            cell.add(new RtfPageNumber());
            cell.setBorderWidth(0);
            specialCell = true;
        }
    } else if (bandElement instanceof ExpressionBandElement) {
        // special case pageNo inside an expression
        // bandName is not important here (it is used for groupRow
        // computation)
        PrefixSuffix pf = interpretPageNo(bandElement);
        if (pf != null) {
            updateFont(fnt, style);
            cell = new RtfCell();
            if (!"".equals(pf.getPrefix())) {
                cell.add(new Phrase(pf.getPrefix(), fnt));
            }
            cell.add(new RtfPageNumber(fnt));
            if (!"".equals(pf.getSuffix())) {
                cell.add(new Phrase(pf.getSuffix(), fnt));
            }
            specialCell = true;
        }
    } else if (bandElement instanceof ImageColumnBandElement) {
        try {
            String v = StringUtil.getValueAsString(value, null);
            if (StringUtil.BLOB.equals(v)) {
                cell = new RtfCell(new Phrase(StringUtil.BLOB));
            } else {
                ImageColumnBandElement icbe = (ImageColumnBandElement) bandElement;
                byte[] imageD = StringUtil.decodeImage(v);
                byte[] imageBytes = getImage(imageD, icbe.getWidth(), icbe.getHeight());
                cell = new RtfCell(Image.getInstance(imageBytes));
            }
        } catch (Exception e) {
            cell = new RtfCell(IMAGE_NOT_LOADED);
        }
        specialCell = true;
    }
    if (!specialCell) {
        if (style.containsKey(StyleFormatConstants.PATTERN)) {
            stringValue = StringUtil.getValueAsString(value, (String) style.get(StyleFormatConstants.PATTERN),
                    getReportLanguage());
        } else {
            stringValue = StringUtil.getValueAsString(value, null, getReportLanguage());
        }
        if (stringValue == null) {
            stringValue = "";
        }
        Phrase ph;
        if (stringValue.startsWith("<html>")) {
            StringReader reader = new StringReader(stringValue);
            List<Element> elems = new ArrayList<Element>();
            try {
                elems = HTMLWorker.parseToList(reader, new StyleSheet());
                ph = new Phrase();
                for (int i = 0; i < elems.size(); i++) {
                    Element elem = (Element) elems.get(i);
                    ph.add(elem);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                ph = new Phrase(stringValue, fnt);
            }
        } else {
            ph = new Phrase(stringValue, fnt);
        }

        try {
            cell = new RtfCell(ph);
        } catch (BadElementException e) {
            e.printStackTrace();
            cell = new RtfCell(stringValue);
        }
    }

    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

    if (colSpan > 1) {
        cell.setColspan(colSpan);
    }

    if (rowSpan > 1) {
        cell.setRowspan(rowSpan);
    }

    setCellStyle(fnt, style, cell);

    return cell;
}

From source file:sg.edu.nus.util.ReportWriter.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // Add a  little list
    createList(subCatPart);//from  w  w w.  ja  v  a  2s. c  om

    // Add a small table
    createTable(subCatPart);
    // Now a small table

    // Now add all this to the document
    document.add(catPart);

    // Next section
    anchor = new Anchor("Second Chapter", catFont);
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // Now add all this to the document
    document.add(catPart);

}