Example usage for com.itextpdf.text Chunk Chunk

List of usage examples for com.itextpdf.text Chunk Chunk

Introduction

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

Prototype

private Chunk(final Float tabInterval, final boolean isWhitespace) 

Source Link

Document

Creates a tab Chunk.

Usage

From source file:nwk.com.br.documents.OrcamentoPdf.java

private PdfPTable cabecalho(Orcamento orcamento) throws Exception {

    //Cria Uma nova tabela com tres colunas, onde cada uma ocupa 20%, 20% e 60% do tamanho delas
    PdfPTable cabecalho = new PdfPTable(new float[] { 0.3f, 0.4f, 0.3f });
    cabecalho.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento
    cabecalho.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    cabecalho.getDefaultCell().setBorder(0);

    //Instancia a imagem da logo da empresa
    Image img = Image.getInstance("logoorc.png");//instancia a imagem
    img.setAlignment(Element.ALIGN_CENTER);//alinha a imagem no centro

    //Cria uma linha da tabela que pegara 3 linhas com a logo nela
    PdfPCell logo = new PdfPCell(img);
    logo.setBorder(0);//w  w w  . ja v a 2 s  .co m
    logo.setRowspan(3);

    //adiciona a logo a tabela
    cabecalho.addCell(logo);

    //adiciona informaes da empresa a tabela
    cabecalho.addCell(new Phrase(new Chunk("Sos da Piscina", f)));
    cabecalho.addCell(new Phrase(new Chunk(formatDate.format(orcamento.getDhOrcamento()).toString(), f)));
    cabecalho.addCell(new Phrase(new Chunk("Avenida Rebouas, 1440 - Centro", f)));
    cabecalho.addCell(new Phrase(new Chunk("Sumar/SP - 13170-140", f)));
    cabecalho.addCell(new Phrase(new Chunk("contato@sosdapiscina.com.br", f)));
    cabecalho.addCell(new Phrase(new Chunk("www.sosdapiscina.com.br", f)));
    cabecalho.addCell(new Phrase(new Chunk("", f)));

    return cabecalho;
}

From source file:org.agmip.ui.afsirs.util.AFSIRSUtils.java

private void addParagraphToTableSoilName(PdfPTable t, String key, String value) {
    PdfPCell c;/*from   w  ww . j a  va2  s .  c  om*/
    Paragraph p = new Paragraph();

    Chunk keyChunk = new Chunk(key, BLACK_NORMAL);
    Chunk valChunk = new Chunk(value, BLACK_BOLD);

    p.add(keyChunk);
    p.add(valChunk);

    c = new PdfPCell(p);
    c.setHorizontalAlignment(Element.ALIGN_CENTER);
    c.setBorder(0);
    t.addCell(c);
}

From source file:org.agmip.ui.afsirs.util.AFSIRSUtils.java

private void addUserDetails(PdfPTable t, String key, String value) {
    PdfPCell c;//  w ww  .  j a  va 2 s  .  c o  m
    Paragraph p = new Paragraph();

    Chunk keyChunk = new Chunk(key, BLACK_NORMAL);
    Chunk valChunk = new Chunk(value, BLACK_BOLD);

    p.add(keyChunk);
    p.add(valChunk);

    c = new PdfPCell(p);
    c.setHorizontalAlignment(Element.ALIGN_LEFT);
    c.setBorder(0);
    t.addCell(c);
}

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.displaytag.sample.decorators.ItextTotalWrapper.java

License:Open Source License

/**
 * Obtain a cell with the given value./*from  w  w w.  ja v a2  s. co m*/
 * @param value Value to display in the cell.
 * @return A cell with the given value.
 */
private PdfPCell getCell(String value) {
    PdfPCell cell = new PdfPCell(new Phrase(new Chunk(value, this.font)));
    cell.setLeading(8, 0);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    return cell;
}

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 va 2 s .  c o  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.flowable.app.rest.runtime.RelatedContentResource.java

License:Apache License

void createPdf(String dest, ArrayList<String> info) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();// w w  w  .  j  ava2 s  . c  o m
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Chunk chunk = new Chunk("Relatrio", chapterFont);
    Chapter chapter = new Chapter(new Paragraph(chunk), 1);
    chapter.setNumberDepth(0);

    int i = 0;
    for (; i < info.size(); i++) {
        chapter.add(new Paragraph(info.get(i), paragraphFont));
    }
    document.add(chapter);
    document.close();
}

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);//w ww . j av a 2s .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();
}

From source file:org.larz.dom4.editor.ReportGenerator.java

License:Open Source License

private static PdfPTable getTable(String[] columns, String[] columnNames, ValueTranslator[] trans,
        ValueCombiner[] combine, List<Map.Entry<String, ModObject>> list) {
    PdfPTable table = new PdfPTable(columns.length);
    table.setWidthPercentage(100f);/*from w  ww .  j  a v  a  2  s  .  co  m*/
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    for (String col : columnNames) {
        PdfPCell c = new PdfPCell(new Phrase(col, SUBTITLE));
        c.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(c);
    }
    table.setHeaderRows(1);

    for (Map.Entry<String, ModObject> innerEntry : list) {
        String name = innerEntry.getValue().title;
        Map<String, PropertyValues> map = innerEntry.getValue().propertyMap;

        List<Map.Entry<String, PropertyValues>> list2 = new ArrayList<Map.Entry<String, PropertyValues>>();
        for (Map.Entry<String, PropertyValues> innerEntry2 : map.entrySet()) {
            list2.add(innerEntry2);
        }
        Collections.sort(list2, new Comparator<Map.Entry<String, PropertyValues>>() {
            @Override
            public int compare(Map.Entry<String, PropertyValues> o1, Map.Entry<String, PropertyValues> o2) {
                return o1.getKey().compareTo(o2.getKey());
            }
        });

        if (list2.size() == 0)
            continue;

        PdfPCell[] cells = new PdfPCell[columns.length];
        cells[0] = new PdfPCell();
        cells[0].addElement(new Phrase(name, BOLD_TEXT));

        for (int i = 1; i < cells.length; i++) {
            cells[i] = new PdfPCell();
            if (combine != null && combine[i] != null) {
                String[] neededCols = combine[i].getNeededColumns();
                String[] oldValues = new String[neededCols.length];
                String[] newValues = new String[neededCols.length];
                for (int j = 0; j < neededCols.length; j++) {
                    for (Map.Entry<String, PropertyValues> entry : list2) {
                        if (entry.getKey().equals(neededCols[j])) {
                            oldValues[j] = entry.getValue().oldValue;
                            newValues[j] = entry.getValue().newValue;
                            break;
                        }
                    }
                }
                // Put old values into null new values
                boolean hasNew = false;
                for (int k = 0; k < newValues.length; k++) {
                    if (newValues[k] != null) {
                        hasNew = true;
                        break;
                    }
                }
                if (hasNew) {
                    for (int k = 0; k < newValues.length; k++) {
                        if (newValues[k] == null) {
                            newValues[k] = oldValues[k];
                        }
                    }
                }
                String newValue = combine[i].translate(newValues);
                String oldValue = combine[i].translate(oldValues);
                if (newValue != null) {
                    Phrase phrase = new Phrase();
                    phrase.add(new Chunk(newValue, BOLD_TEXT));
                    if (oldValue != null) {
                        phrase.add(new Chunk(" (" + oldValue + ")", TEXT));
                    }
                    cells[i].addElement(phrase);
                } else if (oldValue != null) {
                    cells[i].addElement(new Phrase(oldValue, TEXT));
                }
            } else {
                for (Map.Entry<String, PropertyValues> entry : list2) {
                    if (entry.getKey().equals(columns[i])) {
                        String oldValue = entry.getValue().oldValue;
                        String newValue = entry.getValue().newValue;
                        if (trans != null && trans.length > i && trans[i] != null) {
                            oldValue = trans[i].translate(oldValue);
                            newValue = trans[i].translate(newValue);
                        }
                        if (newValue != null) {
                            Phrase phrase = new Phrase();
                            phrase.add(new Chunk(newValue, BOLD_TEXT));
                            if (oldValue != null && !oldValue.equals("null")) {
                                phrase.add(new Chunk(" (" + oldValue + ")", TEXT));
                            }
                            cells[i].addElement(phrase);
                        } else if (oldValue != null && !oldValue.equals("null")) {
                            cells[i].addElement(new Phrase(oldValue, TEXT));
                        }
                        break;
                    }
                }
            }
        }

        for (PdfPCell cell : cells) {
            table.addCell(cell);
        }
    }
    return table;
}

From source file:org.openlmis.web.view.pdf.requisition.RequisitionCellFactory.java

License:Open Source License

public static PdfPCell headingCell(String value) {
    Chunk chunk = new Chunk(value, H2_FONT);
    PdfPCell cell = new PdfPCell(new Phrase(chunk));
    cell.setPadding(CELL_PADDING);//from   w  w  w .  ja va2  s .  c  o  m
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    return cell;
}