Example usage for com.itextpdf.text Paragraph add

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

Introduction

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

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:org.bonitasoft.studio.migration.utils.PDFMigrationReportWriter.java

License:Open Source License

private void createLegend(Paragraph mainPara) throws BadElementException, MalformedURLException, IOException {
    mainPara.add(new Chunk("      ", legendFont));
    Image im = getImageForStatus(IStatus.OK);
    mainPara.add(new Chunk(im, 0, 0, false));
    mainPara.add(new Chunk(" ", legendFont));
    mainPara.add(new Chunk(Messages.noActionRequired, legendFont));
    mainPara.add(new Chunk("   ", legendFont));
    im = getImageForStatus(IStatus.WARNING);
    mainPara.add(new Chunk(im, 0, 0, false));
    mainPara.add(new Chunk(" ", legendFont));
    mainPara.add(new Chunk(Messages.reviewRequired, legendFont));
    mainPara.add(new Chunk("   ", legendFont));
    im = getImageForStatus(IStatus.ERROR);
    mainPara.add(new Chunk(im, 0, 0, false));
    mainPara.add(new Chunk(" ", legendFont));
    mainPara.add(new Chunk(Messages.actionRequired, legendFont));
}

From source file:org.bonitasoft.studio.migration.utils.PDFMigrationReportWriter.java

License:Open Source License

private void createTable(Paragraph paragrah) throws MalformedURLException, IOException, DocumentException {
    PdfPTable table = new PdfPTable(6);
    table.setHeaderRows(0);// w w  w  . ja  v a  2  s.c om
    table.setWidthPercentage(95f);
    PdfPCell c1 = new PdfPCell(new Phrase(Messages.elementType));
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setVerticalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(Messages.name));
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setVerticalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(Messages.property));
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setVerticalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(Messages.information));
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setVerticalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(Messages.status));
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setVerticalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(Messages.reviewed));
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setVerticalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    table.setHeaderRows(1);

    List<Change> changes = report.getChanges();
    if (viewer != null) {
        for (int i = 0; i < changes.size(); i++) {
            addTableRow(table, (Change) viewer.getElementAt(i));
        }
    } else {
        for (Change change : changes) {
            addTableRow(table, change);
        }
    }

    table.setWidths(new int[] { 3, 3, 3, 5, 2, 2 });
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.setComplete(true);

    paragrah.add(table);
}

From source file:org.cidte.sii.negocio.PDFWriter.java

public void writePDF(ArrayList<Writable> list, String directorio, String nombre, java.awt.Image image)
        throws DocumentException, FileNotFoundException, BadElementException, IOException {

    Document doc = new Document();
    PdfWriter docWriter;//from  ww w  . j ava2 s  .  c o  m

    // special font sizes
    Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
    Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12);

    // file path
    String path = directorio + nombre + ".pdf";
    docWriter = PdfWriter.getInstance(doc, new FileOutputStream(new File(path)));

    // document header attributes
    doc.addAuthor("sii");
    doc.addCreationDate();
    doc.addProducer();
    doc.addCreator("sii");
    doc.addTitle(nombre);
    doc.setPageSize(PageSize.LETTER);

    // open document
    doc.open();

    Image img = Image.getInstance(image, null);
    img.setAlignment(Element.ALIGN_LEFT);
    doc.add(img);

    // create a paragraph
    Paragraph paragraph = new Paragraph("iText  is a library that allows you to create and "
            + "manipulate PDF documents. It enables developers looking to enhance web and other "
            + "applications with dynamic PDF document generation and/or manipulation.");

    // create PDF table with the given widths
    PdfPTable table = new PdfPTable(list.get(0).getNames().length);
    // set table width a percentage of the page width
    table.setWidthPercentage(100);
    table.setSpacingBefore(10f); // Space before table
    table.setSpacingAfter(10f); // Space after table

    // insert column headings
    String[] headings = list.get(0).getNames();
    for (String heading : headings) {
        insertCell(table, heading, Element.ALIGN_CENTER, 1, bfBold12);
    }
    table.setHeaderRows(1);

    // insert the data
    for (int i = 0; i < list.size(); i++) {
        Writable w = list.get(i);
        Object[] arr = w.getAsArray();
        for (int j = 0; j < arr.length; j++) {
            // arr[j]
            insertCell(table, arr[j].toString(), Element.ALIGN_LEFT, 1, bf12);
        }
    }

    // insert an empty row
    // insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);
    // add the PDF table to the paragraph
    paragraph.add(table);
    // add the paragraph to the document
    doc.add(paragraph);

    // close the document
    doc.close();

    // close the writer
    docWriter.close();

}

From source file:org.dspace.disseminate.CitationDocument.java

/**
 * Takes a DSpace {@link Bitstream} and uses its associated METADATA to
 * create a cover page./*from w  w w.j a  v a 2s.  co  m*/
 *
 * @param cDoc The cover page document to add cited information to.
 * @param writer
 * @param cMeta
 *            METADATA retrieved from the parent collection.
 * @throws IOException
 * @throws DocumentException
 */
private void generateCoverPage(Document cDoc, PdfWriter writer, CitationMeta cMeta) throws DocumentException {
    cDoc.open();
    writer.setCompressionLevel(0);

    Item item = cMeta.getItem();

    //Set up some fonts
    Font helv26 = FontFactory.getFont(FontFactory.HELVETICA, 26f, BaseColor.BLACK);
    Font helv16 = FontFactory.getFont(FontFactory.HELVETICA, 16f, BaseColor.BLACK);
    Font helv12 = FontFactory.getFont(FontFactory.HELVETICA, 12f, BaseColor.BLACK);
    Font helv12_italic = FontFactory.getFont(FontFactory.HELVETICA_OBLIQUE, 12f, BaseColor.BLACK);
    Font helv11_bold = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11f, BaseColor.BLACK);
    Font helv9 = FontFactory.getFont(FontFactory.HELVETICA, 9f, BaseColor.BLACK);

    // 1 - Header:
    //  University Name
    //  Repository Name                                                        repository.url
    Paragraph university = new Paragraph("The Ohio State University", helv11_bold);
    cDoc.add(university);

    PdfPTable repositoryTable = new PdfPTable(2);
    repositoryTable.setWidthPercentage(100);

    Chunk repositoryName = new Chunk("Knowledge Bank", helv11_bold);
    PdfPCell nameCell = new PdfPCell();
    nameCell.setBorderWidth(0);
    nameCell.addElement(repositoryName);

    Chunk repositoryURL = new Chunk("kb.osu.edu", helv11_bold);
    repositoryURL.setAnchor("http://kb.osu.edu");

    PdfPCell urlCell = new PdfPCell();
    urlCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    urlCell.setBorderWidth(0);
    urlCell.addElement(repositoryURL);

    repositoryTable.addCell(nameCell);
    repositoryTable.addCell(urlCell);

    repositoryTable.setSpacingAfter(5);

    cDoc.add(repositoryTable);

    // Line Separator
    LineSeparator lineSeparator = new LineSeparator();
    cDoc.add(lineSeparator);

    // 2 - Bread Crumbs
    // Community Name                                                          Collection Name
    PdfPTable breadcrumbTable = new PdfPTable(2);
    breadcrumbTable.setWidthPercentage(100);

    Chunk communityName = new Chunk(getOwningCommunity(item), helv9);
    PdfPCell commCell = new PdfPCell();
    commCell.setBorderWidth(0);
    commCell.addElement(communityName);

    Chunk collectionName = new Chunk(getOwningCollection(item), helv9);
    PdfPCell collCell = new PdfPCell();
    collCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    collCell.setBorderWidth(0);
    collCell.addElement(collectionName);

    breadcrumbTable.addCell(commCell);
    breadcrumbTable.addCell(collCell);

    breadcrumbTable.setSpacingBefore(5);
    breadcrumbTable.setSpacingAfter(5);

    cDoc.add(breadcrumbTable);

    // Line Separator
    cDoc.add(lineSeparator);

    // 3 - Metadata
    // date.issued
    // dc.title
    // dc.creator; dc.creator
    Paragraph dateIssued = new Paragraph(getFirstMetadata(item, "dc.date.issued"), helv12);
    dateIssued.setSpacingBefore(20);
    cDoc.add(dateIssued);

    Paragraph title = new Paragraph(item.getName(), helv26);
    title.setSpacingBefore(15);
    cDoc.add(title);

    Paragraph creators = new Paragraph(getAllMetadataSeperated(item, "dc.creator"), helv16);
    creators.setSpacingBefore(30);
    creators.setSpacingAfter(20);
    cDoc.add(creators);

    // Line Separator
    cDoc.add(lineSeparator);

    // 4 - Citation
    // dc.identifier.citation
    // dc.identifier.uri
    Paragraph citation = new Paragraph(getFirstMetadata(item, "dc.identifier.citation"), helv12);

    Chunk identifierChunk = new Chunk(getFirstMetadata(item, "dc.identifier.uri"), helv12);
    identifierChunk.setAnchor(getFirstMetadata(item, "dc.identifier.uri"));

    Paragraph identifier = new Paragraph();
    identifier.add(identifierChunk);

    cDoc.add(citation);
    cDoc.add(identifier);

    // 5 - License
    // Downloaded from the Knowledge Bank, The Ohio State University's institutional repository
    Paragraph license = new Paragraph(
            "Downloaded from the Knowledge Bank, The Ohio State University's institutional repository",
            helv12_italic);
    license.setSpacingBefore(10);
    cDoc.add(license);

    cDoc.close();
}

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

License:Open Source License

private void addFooter(LebData lebData, PdfWriter writer) throws DocumentException, PdfFormatierungsException {
    int footerMargin = 0;
    if (lebData.getSchulhalbjahr().isErstesHalbjahr()) {
        footerMargin = bottomMargin + 85;
    } else {/* ww w.  jav a 2 s  .  c om*/
        footerMargin = bottomMargin + 170;
    }
    alertLonelyFooter(writer, footerMargin);
    while (writer.getVerticalPosition(false) > (footerMargin + 20)) {
        document.add(Chunk.NEWLINE);
    }
    float footerBegin = writer.getVerticalPosition(false);
    Paragraph footerTopParagraph = new Paragraph();
    footerTopParagraph.setLeading(1, 0.4f);
    footerTopParagraph.add(Chunk.NEWLINE);
    footerTopParagraph.add(Chunk.NEWLINE);

    Paragraph footerBottompParagraph = new Paragraph();
    footerBottompParagraph.setLeading(1, 0.4f);

    if (lebData.getSchulhalbjahr().isErstesHalbjahr()) {
        footerTopParagraph
                .add(PdfFormatHelper.buildFooterHalbjahrDatumLine(lebData.getDatumString(), footerFont));
        footerTopParagraph.add(PdfFormatHelper.buildFooterHalbjahrDatumKlassenleiterLine(footerFont));
    } else {
        footerTopParagraph.add(
                PdfFormatHelper.buildFooterVersetzungsvermerkLine(lebData.getVersetzungsvermerk(), footerFont));
        footerTopParagraph.add(Chunk.NEWLINE);
        footerTopParagraph.add(PdfFormatHelper.buildFooterDatumLine(lebData.getDatumString(), footerFont));
        document.add(footerTopParagraph);
        while (writer.getVerticalPosition(false) > (footerBegin - 82)) {
            document.add(Chunk.NEWLINE);
        }
        footerBottompParagraph.add(PdfFormatHelper.buildFooterDienstsiegelLine(footerFont));
        footerBottompParagraph.add(Chunk.NEWLINE);
        footerBottompParagraph.add(PdfFormatHelper.buildFooterUnterschriftenLine(footerFont));
    }
    footerBottompParagraph.add(Chunk.NEWLINE);
    footerBottompParagraph.add(Chunk.NEWLINE);
    footerBottompParagraph.add(Chunk.NEWLINE);
    footerBottompParagraph.add(PdfFormatHelper.buildFooterKenntnisLine(footerFont));
    document.add(footerBottompParagraph);
}

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

License:Open Source License

private void addContent(PdfWriter writer) throws DocumentException, PdfFormatierungsException {
    Anchor anchor = new Anchor("Lernentwicklungsbericht", lernentwicklungsberichtUeberschriftFont);
    Chapter chapterLEB = new Chapter(new Paragraph(anchor), 1);
    chapterLEB.setNumberDepth(0);//from w w  w.ja va 2 s.com
    Paragraph paragraphHeader = new Paragraph();
    paragraphHeader.setLeading(FIXED_LEADING_TEXT, 1);
    sectionCount += 1;
    Section headerSection = chapterLEB.addSection(paragraphHeader);
    headerSection.setNumberDepth(0);

    paragraphHeader.add(Chunk.NEWLINE);
    paragraphHeader.add(PdfFormatHelper.buildHeaderNameLine(lebData.getSchuelername(), headerFont));
    paragraphHeader.add(Chunk.NEWLINE);
    paragraphHeader.add(PdfFormatHelper.buildHeaderKlassendatenLine(lebData, headerFont));
    headerSection.add(Chunk.NEWLINE);
    headerSection.add(Chunk.NEWLINE);
    document.add(chapterLEB);
    insertDummyLineIfNecessary(writer);

    addKlassenbrief(chapterLEB, writer);
    addIndividuelleEinschaetzung(chapterLEB, writer);
    addFacheinschaetzungen(chapterLEB, writer);
}

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

License:Open Source License

private void addFacheinschaetzungen(Chapter chapterLEB, PdfWriter writer)
        throws DocumentException, PdfFormatierungsException {
    for (LebFacheinschaetzungData facheinschaetzungsdaten : lebData.getFacheinschaetzungsdaten()) {
        sectionCount += 1;/*from   w ww .  jav a 2  s.c  o  m*/
        breakHurenkind(writer);
        breakSchusterjunge(writer);
        Paragraph paragraphFacheinschaetzung = new Paragraph();
        Section facheinschaetzungsTextSection = chapterLEB.addSection(paragraphFacheinschaetzung);
        facheinschaetzungsTextSection.setNumberDepth(0);
        Collection<String> fachbezeichnungen = facheinschaetzungsdaten.getFachbezeichnungen();
        fachbezeichnungen.add(facheinschaetzungsdaten.getFachname());

        String facheinschaetzung = facheinschaetzungsdaten.getFacheinschaetzung();

        Integer firstIndex = null;
        String boldedWord = "";
        for (String fachbezeichnung : fachbezeichnungen) {
            int index = facheinschaetzung.toLowerCase().indexOf(fachbezeichnung.toLowerCase());
            if (index != -1 && (firstIndex == null || firstIndex > index)) {
                firstIndex = index;
                boldedWord = fachbezeichnung;
            }
        }
        Paragraph facheinschaetzungParapgraph = new Paragraph();
        facheinschaetzungParapgraph.setAlignment(Element.ALIGN_JUSTIFIED);
        facheinschaetzungParapgraph.setLeading(FIXED_LEADING_TEXT, zeilenabstandsfaktor);
        if (firstIndex == null) {
            facheinschaetzungParapgraph.add(new Phrase(
                    facheinschaetzungsdaten.getFacheinschaetzung().replace('\t', '\0'), standardTextFont));
        } else {
            String beforeBoldWord = facheinschaetzung.substring(0, firstIndex);
            facheinschaetzungParapgraph.add(new Phrase(beforeBoldWord.replace('\t', '\0'), standardTextFont));

            String boldWord = facheinschaetzung.substring(firstIndex, firstIndex + boldedWord.length());
            facheinschaetzungParapgraph.add(new Phrase(boldWord, standardTextBoldFont));

            String afterBoldWord = facheinschaetzung.substring(firstIndex + boldedWord.length());
            facheinschaetzungParapgraph.add(new Phrase(afterBoldWord.replace('\t', '\0'), standardTextFont));
        }
        facheinschaetzungParapgraph.setFont(standardTextFont);
        facheinschaetzungsTextSection.add(facheinschaetzungParapgraph);
        Paragraph unterschriftParagraph = new Paragraph();
        document.add(facheinschaetzungsTextSection);
        Section facheinschaetzungsUnterschriftSection = chapterLEB.addSection(unterschriftParagraph);
        facheinschaetzungsUnterschriftSection.setNumberDepth(0);
        unterschriftParagraph.add(
                new Phrase(facheinschaetzungsdaten.getUnterschrift().replace('\t', '\0'), standardTextFont));
        unterschriftParagraph.setAlignment(Element.ALIGN_RIGHT);
        unterschriftParagraph.add(Chunk.NEWLINE);
        unterschriftParagraph.add(Chunk.NEWLINE);
        document.add(facheinschaetzungsUnterschriftSection);
        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;/*  www .  j a v a2  s.c o m*/
        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.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

private Section getKlassenlehrerunterschrift(Section chapterLEB) {
    Paragraph unterschriftParagraph = new Paragraph();
    Section klassenbriefUnterschriftSection = chapterLEB.addSection(unterschriftParagraph);
    klassenbriefUnterschriftSection.setNumberDepth(0);
    unterschriftParagraph
            .add(new Phrase(lebData.getKlassenlehrerUnterschrift().replace('\t', '\0'), standardTextFont));
    unterschriftParagraph.setAlignment(Element.ALIGN_RIGHT);
    unterschriftParagraph.add(Chunk.NEWLINE);
    unterschriftParagraph.add(Chunk.NEWLINE);
    return klassenbriefUnterschriftSection;
}

From source file:org.jaqpot.core.service.data.ReportService.java

public void report2PDF(Report report, OutputStream os) {

    Document document = new Document();
    document.setPageSize(PageSize.A4);/*from ww w . j a  v  a2  s . c  o m*/
    document.setMargins(50, 45, 80, 40);
    document.setMarginMirroring(false);

    try {
        PdfWriter writer = PdfWriter.getInstance(document, os);
        TableHeader event = new TableHeader();
        writer.setPageEvent(event);

    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    document.open();

    /** setup fonts for pdf */
    Font ffont = new Font(Font.FontFamily.UNDEFINED, 9, Font.ITALIC);
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Font tableFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);

    /** print link to jaqpot*/
    Chunk chunk = new Chunk(
            "This report has been automatically created by the JaqpotQuatro report service. Click here to navigate to our official webpage",
            ffont);
    chunk.setAnchor("http://www.jaqpot.org");

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

    Chapter chapter = new Chapter(paragraph, 1);
    chapter.setNumberDepth(0);

    /** get title */
    String title = null;
    if (report.getMeta() != null && report.getMeta().getTitles() != null
            && !report.getMeta().getTitles().isEmpty())
        title = report.getMeta().getTitles().iterator().next();

    /** print title aligned centered in page */
    if (title == null)
        title = "Report";
    chunk = new Chunk(title, chapterFont);
    paragraph = new Paragraph(chunk);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.add(Chunk.NEWLINE);
    paragraph.add(Chunk.NEWLINE);

    chapter.add(paragraph);

    /** report Description */
    if (report.getMeta() != null && report.getMeta().getDescriptions() != null
            && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        paragraph = new Paragraph();
        paragraph.add(new Chunk("Description: ", paragraphFontBold));
        paragraph.add(new Chunk(report.getMeta().getDescriptions().toString().replaceAll(":http", ": http"),
                paragraphFont));
        chapter.add(paragraph);
        chapter.add(Chunk.NEWLINE);
    }

    /** report model, algorithm and/or dataset id */
    if (report.getMeta() != null && report.getMeta().getHasSources() != null
            && !report.getMeta().getHasSources().isEmpty() && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        Iterator<String> sources = report.getMeta().getHasSources().iterator();
        sources.forEachRemaining(o -> {
            if (o != null) {
                String[] source = o.split("/");
                if (source[source.length - 2].trim().equals("model")
                        || source[source.length - 2].trim().equals("algorithm")
                        || source[source.length - 2].trim().equals("dataset")) {
                    Paragraph paragraph1 = new Paragraph();
                    paragraph1.add(new Chunk(source[source.length - 2].substring(0, 1).toUpperCase()
                            + source[source.length - 2].substring(1) + ": ", paragraphFontBold));
                    paragraph1.add(new Chunk(source[source.length - 1], paragraphFont));
                    chapter.add(paragraph1);
                    chapter.add(Chunk.NEWLINE);
                }
            }
        });
    }

    /** report single calculations */
    report.getSingleCalculations().forEach((key, value) -> {
        Paragraph paragraph1 = new Paragraph();
        paragraph1 = new Paragraph();
        paragraph1.add(new Chunk(key + ": ", paragraphFontBold));
        paragraph1.add(new Chunk(value.toString().trim().replaceAll(" +", " "), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    });

    /** report date of completion */
    if (report.getMeta() != null && report.getMeta().getDate() != null) {
        Paragraph paragraph1 = new Paragraph();
        paragraph1.add(new Chunk("Procedure completed on: ", paragraphFontBold));
        paragraph1.add(new Chunk(report.getMeta().getDate().toString(), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    }

    try {
        document.add(chapter);
    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    Integer chapterNumber = 0;

    /** report all_data */
    for (Entry<String, ArrayCalculation> entry : report.getArrayCalculations().entrySet()) {
        String label = entry.getKey();
        ArrayCalculation ac = entry.getValue();
        PdfPTable table = new PdfPTable(ac.getColNames().size() + 1);
        for (Entry<String, List<Object>> row : ac.getValues().entrySet()) {

            try {
                XMLWorkerHelper.getInstance().parseXHtml(w -> {
                    if (w instanceof WritableElement) {
                        List<Element> elements = ((WritableElement) w).elements();
                        for (Element element : elements) {
                            PdfPCell pdfCell = new PdfPCell();
                            pdfCell.addElement(element);
                            table.addCell(pdfCell);
                        }
                    }
                }, new StringReader(row.getKey()));
            } catch (IOException e) {
                e.printStackTrace();
            }

            for (Object o : row.getValue()) {
                table.addCell(o.toString());
            }
            table.completeRow();
        }
        try {
            Chunk tableChunk = new Chunk(label, tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(Chunk.NEWLINE);
            tableChapter.add(table);
            document.newPage();
            document.add(tableChapter);
        } catch (DocumentException ex) {
            throw new InternalServerErrorException(ex);
        }
    }

    /** report plots */
    for (Entry<String, String> entry : report.getFigures().entrySet()) {
        try {
            byte[] valueDecoded = Base64.decodeBase64(entry.getValue());
            Image l = Image.getInstance(valueDecoded);
            document.newPage();
            //image starts at the half's half of pdf page
            l.setAbsolutePosition(0, (document.getPageSize().getHeight() / 2 / 2));
            l.scaleToFit(document.getPageSize());

            Chunk tableChunk = new Chunk(entry.getKey(), tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(l);
            document.add(tableChapter);
        } catch (IOException | DocumentException e) {
            e.printStackTrace();
        }
    }
    document.close();
}