Example usage for com.itextpdf.text Section add

List of usage examples for com.itextpdf.text Section add

Introduction

In this page you can find the example usage for com.itextpdf.text Section add.

Prototype

@Override
public boolean add(final Element element) 

Source Link

Document

Adds a Paragraph, List, Table or another Section to this Section.

Usage

From source file:org.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

private void addIndividuelleEinschaetzung(Chapter chapterLEB, PdfWriter writer)
        throws DocumentException, PdfFormatierungsException {
    if (!lebData.getIndividuelleEinschaetzung().isEmpty()) {
        sectionCount += 1;//from  ww w  . ja v  a 2 s. c  o m
        breakHurenkind(writer);
        breakSchusterjunge(writer);
        Paragraph paragraphIndividuelleEinschaetzung = new Paragraph();
        Section individuelleEinschaetzungsTextSection = chapterLEB
                .addSection(paragraphIndividuelleEinschaetzung);
        individuelleEinschaetzungsTextSection.setNumberDepth(0);
        Paragraph schuelereinschaetzungParapgraph = new Paragraph(
                lebData.getIndividuelleEinschaetzung().replace('\t', '\0'), standardTextFont);
        schuelereinschaetzungParapgraph.setAlignment(Element.ALIGN_JUSTIFIED);
        schuelereinschaetzungParapgraph.setLeading(FIXED_LEADING_TEXT, zeilenabstandsfaktor);
        individuelleEinschaetzungsTextSection.add(schuelereinschaetzungParapgraph);
        document.add(individuelleEinschaetzungsTextSection);
        document.add(getKlassenlehrerunterschrift(chapterLEB));
        alertHurenkind(writer);
        insertDummyLineIfNecessary(writer);
    }
}

From source file:org.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

private void addKlassenbrief(Chapter chapterLEB, PdfWriter writer)
        throws DocumentException, PdfFormatierungsException {
    if (!lebData.getKlassenbrief().isEmpty()) {
        sectionCount += 1;//from  w  w w.java2  s .  c om
        breakSchusterjunge(writer);
        Paragraph paragraphKlassenbrief = new Paragraph();
        Section klassenbriefSection = chapterLEB.addSection(paragraphKlassenbrief);
        klassenbriefSection.setNumberDepth(0);
        Paragraph klasseneinschaetzungParapgraph = new Paragraph(lebData.getKlassenbrief().replace('\t', '\0'),
                standardTextFont);
        klasseneinschaetzungParapgraph.setAlignment(Element.ALIGN_JUSTIFIED);
        klasseneinschaetzungParapgraph.setLeading(FIXED_LEADING_TEXT, zeilenabstandsfaktor);
        klasseneinschaetzungParapgraph.add(Chunk.NEWLINE);
        if (lebData.getIndividuelleEinschaetzung().isEmpty()) {
            klassenbriefSection.add(klasseneinschaetzungParapgraph);
            document.add(klassenbriefSection);
            document.add(getKlassenlehrerunterschrift(chapterLEB));
        } else {
            klasseneinschaetzungParapgraph.add(Chunk.NEWLINE);
            klassenbriefSection.add(klasseneinschaetzungParapgraph);
            document.add(klassenbriefSection);
        }
        alertLonelyHeader(writer);
        insertDummyLineIfNecessary(writer);
    }
}

From source file:org.sharegov.cirm.utils.PDFExportUtil.java

License:Apache License

private static void createTable(Section subCatPart, Json allData) throws DocumentException {

    Json metaData = allData.at("metaData");
    PdfPTable table = null;//from  w w w  .ja  v  a  2 s. c  o  m
    PdfPCell c1 = null;

    int columns = metaData.at("columns").asInteger();
    table = new PdfPTable(columns);
    table.setWidthPercentage(100);
    if (columns == 9) {
        int[] widths = { 10, 20, 12, 12, 4, 6, 6, 8, 8 };
        table.setWidths(widths);
    } else {
        int[] widths = { 10, 25, 12, 12, 4, 6, 6, 8 };
        table.setWidths(widths);
    }
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    c1 = new PdfPCell(new Phrase(metaData.at("boid").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("type").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("fullAddress").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("city").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("zip").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("hasStatus").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("createdDate").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("lastActivityUpdatedDate").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    if (columns == 9) {
        c1 = new PdfPCell(new Phrase(metaData.at("gisColumn").asString(), smallBold));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(c1);
    }
    table.setHeaderRows(1);

    List<Json> data = allData.at("data").asJsonList();
    for (Json dataValue : data) {
        if (!dataValue.at("hasCaseNumber").asString().isEmpty())
            c1 = new PdfPCell(new Phrase(dataValue.at("hasCaseNumber").asString(), smallFont));
        else
            c1 = new PdfPCell(new Phrase(GenUtils.makeCaseNumber(dataValue.at("boid").asLong()), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("label").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("fullAddress").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("Street_Address_City").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("Zip_Code").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("hasStatus").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("hasDateCreated").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("lastActivityUpdatedDate").asString(), smallFont));
        table.addCell(c1);
        if (columns == 9) {
            c1 = new PdfPCell(new Phrase(dataValue.at("gisColumn").asString(), smallFont));
            table.addCell(c1);
        }
    }

    subCatPart.add(table);
}

From source file:org.sharegov.cirm.utils.PDFViewReport.java

License:Apache License

private void addTopTable(Section subCatPart, Json data) throws DocumentException {
    PdfPTable table = new PdfPTable(4);
    table.setWidthPercentage(100);//from w  w  w  .j a v  a 2  s.  c o m
    int[] widths = { 12, 55, 15, 20 };
    table.setWidths(widths);

    PdfPCell cell = null;

    OWLNamedIndividual typeInd = individual(legacyPrefix + data.at("type").asString());
    addCell(cell, table, "Type:", Element.ALIGN_RIGHT, boldFont, null);
    addCell(cell, table, getEntityLabel(typeInd), Element.ALIGN_LEFT, normalFont, null);
    addCell(cell, table, "SR #:", Element.ALIGN_RIGHT, boldFont, null);
    if (data.at("properties").has("hasCaseNumber"))
        addCell(cell, table, data.at("properties").at("hasCaseNumber").asString(), Element.ALIGN_LEFT,
                normalFont, null);
    else
        addCell(cell, table, GenUtils.makeCaseNumber(data.at("boid").asLong()), Element.ALIGN_LEFT, normalFont,
                null);
    //02-20-2014 - Syed add providedby to report
    addCell(cell, table, "Area:", Element.ALIGN_RIGHT, boldFont, null);
    addCell(cell, table, getArea(typeInd), Element.ALIGN_LEFT, normalFont, null);
    addCell(cell, table, "Priority:", Element.ALIGN_RIGHT, boldFont, null);
    addCell(cell, table, data.at("properties").at("hasPriority").at("label").asString(), Element.ALIGN_LEFT,
            normalFont, null);
    addCell(cell, table, "Group:", Element.ALIGN_RIGHT, boldFont, null);
    addCell(cell, table, getGroup(typeInd), Element.ALIGN_LEFT, normalFont, null);
    addCell(cell, table, "Status:", Element.ALIGN_RIGHT, boldFont, null);
    addCell(cell, table, getEntityLabel(individual(data.at("properties"), "hasStatus")), Element.ALIGN_LEFT,
            normalFont, null);

    addCell(cell, table, "Jurisdiction:", Element.ALIGN_RIGHT, boldFont, null);
    OWLLiteral jurisdiction = dataProperty(typeInd, legacyPrefix + "hasJurisdictionDescription");
    addCell(cell, table, jurisdiction != null ? jurisdiction.getLiteral() : emptyField, Element.ALIGN_LEFT,
            normalFont, null);
    addCell(cell, table, "Status Date:", Element.ALIGN_RIGHT, boldFont, null);
    String modifiedDate = data.at("properties").has("hasDateLastModified")
            ? data.at("properties").at("hasDateLastModified").asString()
            : "";
    addCell(cell, table, formatDate(modifiedDate, true, false), Element.ALIGN_LEFT, normalFont, null);

    addCell(cell, table, "Input By:", Element.ALIGN_RIGHT, boldFont, null);
    String inputBy = data.at("properties").has("isCreatedBy")
            ? data.at("properties").at("isCreatedBy").asString()
            : emptyField;
    addCell(cell, table, inputBy, Element.ALIGN_LEFT, normalFont, null);
    addCell(cell, table, "Created Date:", Element.ALIGN_RIGHT, boldFont, null);
    String createdDate = data.at("properties").has("hasDateCreated")
            ? data.at("properties").at("hasDateCreated").asString()
            : "";
    addCell(cell, table, formatDate(createdDate, true, false), Element.ALIGN_LEFT, normalFont, null);

    addCell(cell, table, "CC Groups:", Element.ALIGN_RIGHT, boldFont, null);
    addCell(cell, table, blankField, Element.ALIGN_LEFT, normalFont, null);
    addCell(cell, table, "Created By:", Element.ALIGN_RIGHT, boldFont, null);
    addCell(cell, table, getEmployeeName(inputBy), Element.ALIGN_LEFT, normalFont, null);

    addCell(cell, table, "Location:", Element.ALIGN_RIGHT, boldFont, null);
    addCell(cell, table,
            data.at("properties").has("atAddress") ? buildAddress(data.at("properties").at("atAddress"))
                    : blankField,
            Element.ALIGN_LEFT, normalFont, null);
    addCell(cell, table, "Method Received:", Element.ALIGN_RIGHT, boldFont, null);
    addCell(cell, table, data.at("properties").at("hasIntakeMethod").at("label").asString(), Element.ALIGN_LEFT,
            normalFont, null);

    subCatPart.add(table);
    subCatPart.add(new Chunk(new LineSeparator()));
}

From source file:org.sharegov.cirm.utils.PDFViewReport.java

License:Apache License

private void addDescription(Section subCatPart, Json data) throws DocumentException {
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);//ww  w  . j a va  2 s  .  co m
    int[] widths = { 15, 85 };
    table.setWidths(widths);

    PdfPCell cell = null;

    addCell(cell, table, "Description:", Element.ALIGN_LEFT, bigBoldFont, null);
    if (data.at("properties").has("hasDetails"))
        addCell(cell, table, data.at("properties").at("hasDetails").asString(), Element.ALIGN_LEFT, normalFont,
                null);

    subCatPart.add(table);
    subCatPart.add(new Chunk(new LineSeparator()));
}

From source file:org.sharegov.cirm.utils.PDFViewReport.java

License:Apache License

private void addQuestions(Section subCatPart, Json data)
        throws DocumentException, UnsupportedEncodingException {
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);/*from w  w w .  j  a v a 2  s. c om*/
    int[] widths = { 65, 35 };
    table.setWidths(widths);

    PdfPCell cell = null;

    addCell(cell, table, "SR Questions", Element.ALIGN_LEFT, bigBoldFont, null);
    addCell(cell, table, "Answers", Element.ALIGN_LEFT, bigBoldFont, null);

    subCatPart.add(table);
    //subCatPart.add(Chunk.NEWLINE);
    //subCatPart.add(new Chunk(new LineSeparator()));

    table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.setWidths(widths);

    OWLNamedIndividual typeInd = individual(legacyPrefix + data.at("type").asString());
    List<Json> allServiceAnswers = new ArrayList<Json>();
    LegacyEmulator.getAllServiceFields(typeInd, allServiceAnswers, true);

    List<Json> saList = getAllServiceAnswers(data);

    for (int k = 0; k < allServiceAnswers.size(); k++) {
        Json serviceAnswer = allServiceAnswers.get(k);
        BaseColor color = addColor(k);
        int counter = 0;
        addCell(cell, table, serviceAnswer.at("hasServiceField").at("label").asString(), Element.ALIGN_LEFT,
                normalFont, color);
        for (Json sa : saList) {
            if (sa.at("hasServiceField").at("iri").asString()
                    .equals(serviceAnswer.at("hasServiceField").at("iri").asString())) {
                OWLIndividual qtn = individual(sa.at("hasServiceField").at("iri").asString());
                OWLObjectProperty cvl = objectProperty(legacyPrefix + "hasChoiceValueList");

                if (sa.has("hasAnswerValue")) {
                    if (sa.at("hasAnswerValue").at("literal").isArray()) {
                        List<Json> literalList = sa.at("hasAnswerValue").at("literal").asJsonList();
                        for (int i = 0; i < literalList.size(); i++) {
                            String eachAns = literalList.get(i).asString();
                            addCell(cell, table, eachAns, Element.ALIGN_LEFT, normalFont, color);
                            if (i != literalList.size() - 1)
                                addCell(cell, table, blankField, Element.ALIGN_LEFT, normalFont, color);
                        }
                    } else {
                        String ans = sa.at("hasAnswerValue").at("literal").asString();
                        if (serviceAnswer.at("hasDataType").asString().equals("NUMBER"))
                            ans = Long.toString(new BigDecimal(ans).longValue());
                        if (serviceAnswer.at("hasDataType").asString().equals("DATE"))
                            ans = formatDate(ans, false, false);
                        addCell(cell, table, ans, Element.ALIGN_LEFT, normalFont, color);

                    }
                } else if (sa.has("hasAnswerObject")) {
                    if (sa.at("hasAnswerObject").isArray()) {
                        List<Json> answerObjectList = sa.at("hasAnswerObject").asJsonList();
                        for (int i = 0; i < answerObjectList.size(); i++) {
                            Json eachAnswerObject = answerObjectList.get(i);
                            //OWL.objectProperties(qtn, cvl.getIRI().toString());
                            if (!OWL.collectObjectProperties(qtn, cvl).isEmpty()
                                    && !containsWhiteSpace(eachAnswerObject.at("iri").asString())) {
                                addCell(cell, table,
                                        getEntityLabel(individual(eachAnswerObject.at("iri").asString())),
                                        Element.ALIGN_LEFT, normalFont, color);
                                if (i != answerObjectList.size() - 1)
                                    addCell(cell, table, blankField, Element.ALIGN_LEFT, normalFont, color);
                            }
                        }
                    } else {
                        String ans = sa.at("hasAnswerObject").at("iri").asString();
                        if (!OWL.collectObjectProperties(qtn, cvl).isEmpty() && !containsWhiteSpace(ans)) {
                            addCell(cell, table, getEntityLabel(individual(ans)), Element.ALIGN_LEFT,
                                    normalFont, color);
                        } else
                            addCell(cell, table, ans, Element.ALIGN_LEFT, normalFont, color);
                    }
                }
                ++counter;
            } else
                continue;
        }
        if (counter == 0)
            addCell(cell, table, emptyField, Element.ALIGN_LEFT, normalFont, color);
    }
    subCatPart.add(table);
    subCatPart.add(new Chunk(new LineSeparator()));
}

From source file:org.sharegov.cirm.utils.PDFViewReport.java

License:Apache License

private void addActors(Section subCatPart, Json data) throws DocumentException {
    if (data.at("properties").has("hasServiceCaseActor")) {
        int iActorHeaderColumns = 5;
        int iActorColumns = 6;
        PdfPTable table = new PdfPTable(iActorHeaderColumns);
        table.setWidthPercentage(100);/*from www  .  j a  v a 2  s .c  o m*/
        int[] headerWidths = { 15, 15, 25, 18, 22 };
        int[] widths = { 15, 15, 25, 18, 5, 17 };
        table.setWidths(headerWidths);
        PdfPCell cell = null;

        addCell(cell, table, "Customer", Element.ALIGN_LEFT, bigBoldFont, null);
        addCell(cell, table, "Name", Element.ALIGN_LEFT, bigBoldFont, null);
        addCell(cell, table, "Address", Element.ALIGN_LEFT, bigBoldFont, null);
        addCell(cell, table, "e-Mail", Element.ALIGN_LEFT, bigBoldFont, null);
        addCell(cell, table, "Contact No", Element.ALIGN_LEFT, bigBoldFont, null);

        subCatPart.add(table);
        //subCatPart.add(Chunk.NEWLINE);
        //subCatPart.add(new Chunk(new LineSeparator()));

        table = new PdfPTable(iActorColumns);
        table.setWidthPercentage(100);
        table.setWidths(widths);

        if (!data.at("properties").at("hasServiceCaseActor").isArray()) {
            data.at("properties").set("hasServiceCaseActor",
                    Json.array().add(data.at("properties").at("hasServiceCaseActor")));
        }

        for (int k = 0; k < data.at("properties").at("hasServiceCaseActor").asJsonList().size(); k++) {
            Json actor = data.at("properties").at("hasServiceCaseActor").at(k);
            BaseColor color = addColor(k);
            OWLNamedIndividual act = individual(actor, "hasServiceActor");
            String actorType = getEntityLabel(act);

            StringBuilder actorName = new StringBuilder();
            if (actor.has("Name"))
                actorName.append(actor.at("Name").asString());
            if (actor.has("LastName")) {
                if (actorName.toString().isEmpty())
                    actorName.append(actor.at("LastName").asString());
                else
                    actorName.append(" ").append(actor.at("LastName").asString());
            }
            if (actorName.toString().isEmpty())
                actorName.append(blankField);

            StringBuilder actorAddr = new StringBuilder();
            if (actor.has("atAddress")) {
                Json addr = actor.at("atAddress");
                if (addr.has("fullAddress"))
                    actorAddr.append(addr.at("fullAddress").asString());
                if (addr.has("Street_Unit_Number"))
                    actorAddr.append(", #").append(addr.at("Street_Unit_Number").asString());
                if (addr.has("Street_Address_City")) {
                    OWLNamedIndividual cityInd = individual(addr, "Street_Address_City");
                    OWLLiteral city = dataProperty(cityInd, "Name");
                    if (city == null)
                        city = dataProperty(cityInd, "Alias");
                    if (city != null)
                        actorAddr.append(", ").append(city.getLiteral());
                }
                if (addr.has("fullAddress") && addr.has("Street_Address_State")) {
                    OWLNamedIndividual stateInd = individual(addr, "Street_Address_State");
                    OWLLiteral state = dataProperty(stateInd, "USPS_Abbreviation");
                    if (state != null)
                        actorAddr.append(", ").append(state.getLiteral());
                }
                if (addr.has("Zip_Code"))
                    actorAddr.append(" - ").append(addr.at("Zip_Code").asString());
            } else
                actorAddr.append(blankField);

            String eMail = actor.has("hasEmailAddress") ? actor.at("hasEmailAddress").isObject()
                    ? actor.at("hasEmailAddress").at("iri").asString().split(":")[1]
                    : actor.at("hasEmailAddress").asString().split(":")[1] : blankField;

            addCell(cell, table, actorType, Element.ALIGN_LEFT, normalFont, color);
            addCell(cell, table, actorName.toString(), Element.ALIGN_LEFT, normalFont, color);
            addCell(cell, table, actorAddr.toString(), Element.ALIGN_LEFT, normalFont, color);
            addCell(cell, table, eMail, Element.ALIGN_LEFT, normalFont, color);

            boolean isFirstContactNo = true;
            String actorHmPh = actor.has("HomePhoneNumber") ? actor.at("HomePhoneNumber").asString() : null;
            String actorCellNo = actor.has("CellPhoneNumber") ? actor.at("CellPhoneNumber").asString() : null;
            String actorBizNo = actor.has("BusinessPhoneNumber") ? actor.at("BusinessPhoneNumber").asString()
                    : null;
            String actorFaxNo = actor.has("FaxNumber") ? actor.at("FaxNumber").asString() : null;
            String actorOtherNo = actor.has("OtherPhoneNumber") ? actor.at("OtherPhoneNumber").asString()
                    : null;

            if (actorHmPh != null)
                isFirstContactNo = addActorsContactNumbers(table, cell, actorHmPh, "Home ", iActorColumns,
                        color, isFirstContactNo);
            if (actorCellNo != null)
                isFirstContactNo = addActorsContactNumbers(table, cell, actorCellNo, "Cell ", iActorColumns,
                        color, isFirstContactNo);
            if (actorBizNo != null)
                isFirstContactNo = addActorsContactNumbers(table, cell, actorBizNo, "Biz ", iActorColumns,
                        color, isFirstContactNo);
            if (actorFaxNo != null)
                isFirstContactNo = addActorsContactNumbers(table, cell, actorFaxNo, "Fax ", iActorColumns,
                        color, isFirstContactNo);
            if (actorOtherNo != null)
                isFirstContactNo = addActorsContactNumbers(table, cell, actorOtherNo, "Other ", iActorColumns,
                        color, isFirstContactNo);
            if (actorHmPh == null && actorCellNo == null && actorBizNo == null && actorFaxNo == null
                    && actorOtherNo == null) {
                addCell(cell, table, blankField, Element.ALIGN_LEFT, normalFont, color);
                addCell(cell, table, blankField, Element.ALIGN_LEFT, normalFont, color);
            }
        }
        subCatPart.add(table);
        subCatPart.add(new Chunk(new LineSeparator()));
    }
}

From source file:org.sharegov.cirm.utils.PDFViewReport.java

License:Apache License

private void addActivities(Section subCatPart, Json data) throws DocumentException {
    if (data.at("properties").has("hasServiceActivity")) {
        if (!data.at("properties").at("hasServiceActivity").isArray()) {
            data.at("properties").set("hasServiceActivity",
                    Json.array().add(data.at("properties").at("hasServiceActivity")));
        }//  www  . j a va2  s.  com
        Json filteredActivities = Json.array();
        //Do not add any StatusChangeActivity Activities to the report
        for (Json act : data.at("properties").at("hasServiceActivity").asJsonList()) {
            OWLNamedIndividual actInd = individual(act, "hasActivity");
            if (!actInd.getIRI().getFragment().equals("StatusChangeActivity"))
                filteredActivities.add(act);
        }

        if (filteredActivities.asJsonList().size() > 0) {
            //PdfPTable table = new PdfPTable(7);
            PdfPTable table = new PdfPTable(6);
            table.setWidthPercentage(100);
            //int[] widths = {17, 13, 12, 12, 13, 13, 20};
            int[] widths = { 25, 20, 13, 12, 13, 17 };
            table.setWidths(widths);
            PdfPCell cell = null;

            addCell(cell, table, "Activity", Element.ALIGN_LEFT, bigBoldFont, null);
            addCell(cell, table, "Assigned To", Element.ALIGN_LEFT, bigBoldFont, null);
            addCell(cell, table, "Created Date", Element.ALIGN_LEFT, bigBoldFont, null);
            addCell(cell, table, "Due Date", Element.ALIGN_LEFT, bigBoldFont, null);
            addCell(cell, table, "Completed Date", Element.ALIGN_LEFT, bigBoldFont, null);
            addCell(cell, table, "Outcome", Element.ALIGN_LEFT, bigBoldFont, null);
            //addCell(cell, table, "Details", Element.ALIGN_LEFT, bigBoldFont);

            subCatPart.add(table);
            //subCatPart.add(Chunk.NEWLINE);
            //subCatPart.add(new Chunk(new LineSeparator()));

            //table = new PdfPTable(7);
            //table = new PdfPTable(6);
            //table.setWidthPercentage(100);
            //table.setWidths(widths);

            //Store all outcome iris(key), labels(value).
            //Because in case of duplicate outcomes all outcome values (except the first) will be a string and not object
            Map<String, String> outcomeMap = new HashMap<String, String>(10);

            //for (int k = 0; k < data.at("properties").at("hasServiceActivity").asJsonList().size(); k++)
            for (int k = 0; k < filteredActivities.asJsonList().size(); k++) {
                Json activity = filteredActivities.at(k);
                BaseColor color = addColor(k);
                OWLIndividual act = individual(activity, "hasActivity");
                OWLLiteral typeLabel = null;
                for (OWLAnnotation ann : OWL.annotations(act.asOWLNamedIndividual())) {
                    if (ann.getProperty().isLabel())
                        typeLabel = (OWLLiteral) ann.getValue();
                }

                String activityType = typeLabel == null ? "" : typeLabel.getLiteral();
                String assignedTo = activity.has("isAssignedTo") ? activity.at("isAssignedTo").asString()
                        : blankField;
                String createdDate = activity.has("hasDateCreated") ? activity.at("hasDateCreated").asString()
                        : blankField;
                String dueDate = activity.has("hasDueDate") ? activity.at("hasDueDate").asString() : blankField;
                String completedDate = activity.has("hasCompletedTimestamp")
                        ? activity.at("hasCompletedTimestamp").asString()
                        : blankField;
                String details = activity.has("hasDetails") ? activity.at("hasDetails").asString() : blankField;
                StringBuilder outcome = new StringBuilder("");
                if (activity.has("hasOutcome")) {
                    if (activity.at("hasOutcome").isObject()) {
                        if (!outcomeMap.containsKey(activity.at("hasOutcome").at("iri").asString())) {
                            outcomeMap.put(activity.at("hasOutcome").at("iri").asString(),
                                    activity.at("hasOutcome").at("label").asString());
                            outcome.append(activity.at("hasOutcome").at("label").asString());
                        }
                    } else if (activity.at("hasOutcome").isString()) {
                        if (outcomeMap.containsKey(activity.at("hasOutcome").asString()))
                            outcome.append(outcomeMap.get(activity.at("hasOutcome").asString()));
                        else
                            outcome.append(OWL.fullIri(activity.at("hasOutcome").asString()).getFragment());
                    }
                }

                //table = new PdfPTable(7);
                table = new PdfPTable(6);
                table.setWidthPercentage(100);
                table.setWidths(widths);

                addCell(cell, table, activityType, Element.ALIGN_LEFT, normalFont, color);
                addCell(cell, table, getEmployeeName(assignedTo), Element.ALIGN_LEFT, normalFont, color);
                addCell(cell, table, formatDate(createdDate, false, false), Element.ALIGN_LEFT, normalFont,
                        color);
                addCell(cell, table, formatDate(dueDate, false, false), Element.ALIGN_LEFT, normalFont, color);
                addCell(cell, table, formatDate(completedDate, true, false), Element.ALIGN_LEFT, normalFont,
                        color);
                addCell(cell, table, outcome.toString(), Element.ALIGN_LEFT, normalFont, color);
                subCatPart.add(table);
                if (!details.equals(blankField)) {
                    table = new PdfPTable(2);
                    table.setWidthPercentage(100);
                    int[] detailsWitdh = { 10, 90 };
                    table.setWidths(detailsWitdh);
                    addCell(cell, table, "Details: ", Element.ALIGN_LEFT, normalFont, color);
                    addCell(cell, table, details, Element.ALIGN_LEFT, normalFont, color);
                    subCatPart.add(table);
                }
            }
            //subCatPart.add(table);
            subCatPart.add(new Chunk(new LineSeparator()));
        }
    }
}

From source file:org.tvd.thptty.management.report.Report.java

@SuppressWarnings("unused")
private void createList(Section subCatPart) {
    List list = new List(true, false, 10);
    list.add(new ListItem("First point"));
    list.add(new ListItem("Second point"));
    list.add(new ListItem("Third point"));
    subCatPart.add(list);
}

From source file:org.tvd.thptty.management.util.Report.java

private 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 list
    createList(subCatPart);//from  w w w. java 2  s . com
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);

    paragraph.setFont(smallBold);
    // Add a table
    paragraph.add(createTable(subCatPart));
    subCatPart.add(paragraph);

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

}