Example usage for com.lowagie.text.pdf PdfPCell PdfPCell

List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell

Introduction

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

Prototype

public PdfPCell() 

Source Link

Document

Constructs an empty PdfPCell.

Usage

From source file:fr.opensagres.xdocreport.itext.extension.TableWithVerticalAlignment.java

License:Open Source License

public static void main(String[] args) {
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    try {/*from   w  w  w.  j a v a 2s . c  o m*/
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("TableWithVerticalAlignment.pdf"));

        document.open();

        PdfPTable table = new PdfPTable(1);
        // PdfPCell cell1 = new PdfPCell();
        // cell1.setVerticalAlignment( Element.ALIGN_BOTTOM );
        // //cell1.setMinimumHeight( 100f );
        // cell1.addElement( new Chunk( "cell1" ) );
        // table.addCell( cell1 );

        PdfPCell cell2 = new PdfPCell();
        Paragraph p = new Paragraph();
        p.add(new Chunk("cellp&"));

        cell2.addElement(p);
        cell2.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell2.setMinimumHeight(38f);
        table.addCell(cell2);

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:fr.univlorraine.mondossierweb.controllers.InscriptionController.java

License:Apache License

private PdfPCell makeCell(String str, Font font) {
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);/*from w w w  . ja va 2 s. c o  m*/
    cell.setPhrase(new Phrase(str, font));
    return cell;
}

From source file:ilarkesto.integration.itext.Cell.java

License:Open Source License

@Override
public Element getITextElement() {
    PdfPCell cell = new PdfPCell();

    cell.setBorderColorTop(getBorderTopColor());
    cell.setBorderColorBottom(getBorderBottomColor());
    cell.setBorderColorLeft(getBorderLeftColor());
    cell.setBorderColorRight(getBorderRightColor());
    cell.setBorderWidthTop(APdfBuilder.mmToPoints(getBorderTopWidth()));
    cell.setBorderWidthBottom(APdfBuilder.mmToPoints(getBorderBottomWidth()));
    cell.setBorderWidthLeft(APdfBuilder.mmToPoints(getBorderLeftWidth()));
    cell.setBorderWidthRight(APdfBuilder.mmToPoints(getBorderRightWidth()));
    cell.setUseBorderPadding(false);// w ww . j a  v a2s.com

    cell.setPadding(0);
    cell.setPaddingTop(APdfBuilder.mmToPoints(getPaddingTop()));
    cell.setPaddingBottom(APdfBuilder.mmToPoints(getPaddingBottom()));
    cell.setPaddingLeft(APdfBuilder.mmToPoints(getPaddingLeft()));
    cell.setPaddingRight(APdfBuilder.mmToPoints(getPaddingRight()));

    cell.setBackgroundColor(getBackgroundColor());
    cell.setExtraParagraphSpace(0);
    cell.setIndent(0);

    cell.setColspan(getColspan());
    for (ItextElement element : elements)
        cell.addElement(element.getITextElement());
    return cell;
}

From source file:ilarkesto.integration.itext.Paragraph.java

License:Open Source License

@Override
public Element getITextElement() {
    com.lowagie.text.Paragraph p = new com.lowagie.text.Paragraph();
    float maxSize = 0;
    for (AParagraphElement element : getElements()) {
        if (element instanceof TextChunk) {
            TextChunk textChunk = (TextChunk) element;
            FontStyle fontStyle = textChunk.getFontStyle();

            FontSelector fontSelector = createFontSelector(fontStyle.getFont(), fontStyle);

            String text = textChunk.getText();
            Phrase phrase = fontSelector.process(text);
            p.add(phrase);//from w  w w . j a  v  a  2s.  c  o  m

            float size = (fontStyle.getSize() * 1.1f) + 1f;
            if (size > maxSize)
                maxSize = PdfBuilder.mmToPoints(size);
        } else if (element instanceof Image) {
            Image image = (Image) element;
            com.lowagie.text.Image itextImage;
            try {
                itextImage = image.getITextElement();
            } catch (Exception ex) {
                log.warn("Including image failed:", image, ex);
                continue;
            }

            if (image.getAlign() != null) {
                itextImage.setAlignment(Image.convertAlign(image.getAlign()) | com.lowagie.text.Image.TEXTWRAP);
                p.add(itextImage);
            } else {
                Chunk chunk = new Chunk(itextImage, 0, 0);
                p.add(chunk);
                float size = image.getHeight() + 3;
                if (size > maxSize)
                    maxSize = size;
            }

        } else {
            throw new RuntimeException("Unsupported paragraph element: " + element.getClass().getName());
        }
    }
    p.setLeading(maxSize);
    p.setSpacingBefore(PdfBuilder.mmToPoints(spacingTop));
    p.setSpacingAfter(PdfBuilder.mmToPoints(spacingBottom));
    if (align != null)
        p.setAlignment(convertAlign(align));
    if (height <= 0)
        return p;

    // wrap in table
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);
    cell.setFixedHeight(PdfBuilder.mmToPoints(height));
    cell.addElement(p);
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100);
    table.addCell(cell);
    return table;
}

From source file:ispyb.common.util.export.PdfExporterSample.java

License:Open Source License

/**
 * Exports the file for viewSample for shipment
 * //  ww  w . j a va2 s.co  m
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportAsPdf() throws Exception {

    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    document.addTitle("exportSamplesView");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);
    HeaderFooter header;

    // header + footer
    if (viewName != null)
        header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc + "  ---  " + viewName),
                false);

    else
        header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc), false);

    header.setAlignment(Element.ALIGN_CENTER);
    header.setBorderWidth(1);
    header.getBefore().getFont().setSize(8);
    HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true);
    footer.setAlignment(Element.ALIGN_RIGHT);
    footer.setBorderWidth(1);
    footer.getBefore().getFont().setSize(6);

    document.setHeader(header);
    document.setFooter(footer);

    document.open();

    if (aList.isEmpty()) {
        document.add(new Paragraph("There is no samples in this report"));
        document.close();
        return baos;
    }
    // Create first table for samples

    int NumColumns = 19;
    PdfPTable table = new PdfPTable(NumColumns);
    int headerwidths[] = { 6, 6, 6, 6, 6, 4, 6, 4, 4, 4, 4, 4, 4, 8, 5, 5, 5, 10, 6 }; // percentage
    table.setWidths(headerwidths);

    table.setWidthPercentage(100); // percentage
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setBorderWidth(1);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    // header
    PdfPCell cell = new PdfPCell();
    table.addCell(new Paragraph("Protein", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample name", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Smp code", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Dewar", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Container", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Loc. in cont.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Space group", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell a", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell b", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell c", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell alpha", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell beta", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell gamma", new Font(Font.HELVETICA, 8)));

    cell = new PdfPCell(new Paragraph("Crystal comments", new Font(Font.HELVETICA, 8)));
    table.addCell(cell);

    table.addCell(new Paragraph("Already observed resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Required resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Min. resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample comments", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample status", new Font(Font.HELVETICA, 8)));

    table.setHeaderRows(1); // this is the end of the table header

    table.getDefaultCell().setBorderWidth(1);
    DecimalFormat df1 = new DecimalFormat("#####0.0");
    DecimalFormat df2 = new DecimalFormat("#####0.00");

    Iterator it = aList.iterator();
    int i = 1;
    String currentContainer = "next";
    String nextContainer = "next";

    while (it.hasNext()) {
        table.getDefaultCell().setGrayFill(0.99f);
        if (i % 2 == 1) {
            table.getDefaultCell().setGrayFill(0.9f);
        }
        BLSample3VO samplefv = (BLSample3VO) it.next();
        LOG.debug("table of datacollections pdf " + samplefv.getBlSampleId());

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null)
            nextContainer = samplefv.getContainerVO().getCode();
        else
            nextContainer = "next";

        // in the case of view sorted by dewar/container, we add a page break afetr each container
        if (sortView.equals("2") && !currentContainer.equals(nextContainer)) {
            document.add(table);
            table.deleteBodyRows();
            document.newPage();
        }

        if (samplefv.getCrystalVO().getProteinVO().getAcronym() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getProteinVO().getAcronym(),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getName() != null)
            table.addCell(new Paragraph(samplefv.getName(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCode() != null)
            table.addCell(new Paragraph(samplefv.getCode(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getDewarVO() != null
                && samplefv.getContainerVO().getDewarVO().getCode() != null)
            table.addCell(new Paragraph(samplefv.getContainerVO().getDewarVO().getCode(),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null) {
            currentContainer = samplefv.getContainerVO().getCode();
            table.addCell(new Paragraph(currentContainer, new Font(Font.HELVETICA, 8)));
        } else {
            currentContainer = "current";
            table.addCell("");
        }

        if (samplefv.getLocation() != null)
            table.addCell(new Paragraph(samplefv.getLocation(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getSpaceGroup() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getSpaceGroup(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellA() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellA()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellB() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellB()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellC() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellC()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellAlpha() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellAlpha()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellBeta() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellBeta()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellGamma() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellGamma()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getComments() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getComments(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getObservedResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getObservedResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getRequiredResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getRequiredResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getMinimalResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getMinimalResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getComments() != null && samplefv.getComments() != "")
            table.addCell(new Paragraph(samplefv.getComments(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getBlSampleStatus() != null)
            table.addCell(new Paragraph(samplefv.getBlSampleStatus(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (i % 2 == 1) {
            table.getDefaultCell().setGrayFill(0.0f);
        }

        i++;
    }

    document.add(table);

    document.close();

    return baos;
}

From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java

License:Apache License

private void fillTable(ReportModel model, int leftCol, int topRow, int rightCol, int bottomRow, PdfPTable table)
        throws BadElementException, IOException, SaveReportException {
    TableRowModel rowModel = model.getRowModel();
    for (int row = topRow; row < bottomRow; row++) {
        TableRow reportRow = rowModel.getRow(row);

        //Inserts first cell for calculate row height
        PdfPCell firstCell = new PdfPCell();
        firstCell.setBorder(0);/*from   ww  w  . ja v a 2 s.  c o  m*/
        table.addCell(firstCell);

        for (int col = leftCol; col < rightCol; col++) {
            jdbreport.model.Cell srcCell = reportRow.getCellItem(col);
            if (!srcCell.isChild()) {
                PdfPCell pdfCell = writeCell(model, srcCell, row, col);
                table.addCell(pdfCell);
            }
        }

    }
}

From source file:lmcpointofsalessystem.PDFCustomers.java

public PdfPTable getDatas(String tblName) {
    PdfPTable headerTable = new PdfPTable(1);
    String newT = tblName.toString();
    try {/*from   www.  jav a2 s.  co m*/
        rs = s.executeQuery(
                "select C.CustomerID, C.FirstName, C.LastName, C.Address, C.ContactNumber from Customers C"); //alias lang ung "E"
        String columnExe = "";
        columnExe = "CustomerID,FirstName,LastName,Address,ContactNumber";//pdf column names
        String[] colH = columnExe.split(",");
        int colL = 0;
        colL = columnExe.split(",").length;
        headerTable = new PdfPTable(colL);

        for (int x = 0; x < colL; x++) {
            if (colH[x].toString().equals("C.CustomerID")) {
                colH[x] = "OrderNo1";
            } else if (colH[x].toString().equals("C.FirstName")) {
                colH[x] = "O.CustNo";
            } else if (colH[x].toString().equals("C.LastName")) {
                colH[x] = "OrderDate";
            } else if (colH[x].toString().equals("C.Address")) {
                colH[x] = "ItemDesc";
            } else if (colH[x].toString().equals("C.ContactNumber")) {
                colH[x] = "Unit";
            }

            PdfPCell newHeader = new PdfPCell();
            newHeader.addElement(new Paragraph(colH[x]));
            headerTable.addCell(newHeader);
        }

        //System.out.println(""+columnExe);
        rs = st.executeQuery("Select " + columnExe + " from Customers C");
        int colNums = colH.length;
        int colCount = 0;
        while (rs.next() == true) {
            for (int x = 1; x <= colL; x++) {
                colCount += 1;

                PdfPCell newCell = new PdfPCell();
                newCell.addElement(new Paragraph(rs.getString(x)));
                headerTable.setWidthPercentage(90);
                headerTable.addCell(newCell);
            }
        }

        float[] widths2 = new float[colNums];

        for (int i = 0; i < colNums; i++) {
            widths2[i] = 150;
        }
        try {
            headerTable.setWidths(widths2);
        } catch (DocumentException ex) {
            Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (SQLException ex) {
        Logger.getLogger(PDFCustomers.class.getName()).log(Level.SEVERE, null, ex);
    }

    return headerTable;
}

From source file:lmcpointofsalessystem.PDFCustomersEmployee.java

public PdfPTable getDatas(String tblName) {
    PdfPTable headerTable = new PdfPTable(1);
    String newT = tblName.toString();
    try {/*ww w  .j  av  a  2 s.c  o  m*/
        rs = s.executeQuery(
                "select C.CustomerID, C.FirstName, C.LastName, C.Address, C.ContactNumber from Customers C"); //alias lang ung "E"
        String columnExe = "";
        columnExe = "CustomerID,FirstName,LastName,Address,ContactNumber";//pdf column names
        String[] colH = columnExe.split(",");
        int colL = 0;
        colL = columnExe.split(",").length;
        headerTable = new PdfPTable(colL);

        for (int x = 0; x < colL; x++) {
            if (colH[x].toString().equals("C.CustomerID")) {
                colH[x] = "OrderNo1";
            } else if (colH[x].toString().equals("C.FirstName")) {
                colH[x] = "O.CustNo";
            } else if (colH[x].toString().equals("C.LastName")) {
                colH[x] = "OrderDate";
            } else if (colH[x].toString().equals("C.Address")) {
                colH[x] = "ItemDesc";
            } else if (colH[x].toString().equals("C.ContactNumber")) {
                colH[x] = "Unit";
            }

            PdfPCell newHeader = new PdfPCell();
            newHeader.addElement(new Paragraph(colH[x]));
            headerTable.addCell(newHeader);
        }

        //System.out.println(""+columnExe);
        rs = st.executeQuery("Select " + columnExe + " from Customers C");
        int colNums = colH.length;
        int colCount = 0;
        while (rs.next() == true) {
            for (int x = 1; x <= colL; x++) {
                colCount += 1;

                PdfPCell newCell = new PdfPCell();
                newCell.addElement(new Paragraph(rs.getString(x)));
                headerTable.setWidthPercentage(90);
                headerTable.addCell(newCell);
            }
        }

        float[] widths2 = new float[colNums];

        for (int i = 0; i < colNums; i++) {
            widths2[i] = 150;
        }
        try {
            headerTable.setWidths(widths2);
        } catch (DocumentException ex) {
            Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (SQLException ex) {
        Logger.getLogger(PDFCustomersEmployee.class.getName()).log(Level.SEVERE, null, ex);
    }

    return headerTable;
}

From source file:lmcpointofsalessystem.PDFOrders.java

public PdfPTable getDatas(String tblName) {
    ;/*w w  w .  j  ava2s.c  o  m*/
    PdfPTable headerTable = new PdfPTable(1);
    String newT = tblName.toString();
    String col1 = co.tblOrder.getColumnName(0);
    String col2 = co.tblOrder.getColumnName(1);
    int nrow = co.tblModel.getRowCount();
    int ncol = co.tblModel.getColumnCount();
    Object[][] tabledata = new Object[nrow][ncol];
    for (int i = 0; i < nrow; i++) {
        for (int j = 0; j < ncol; j++) {
            tabledata[i][j] = co.tblModel.getValueAt(i, j);
        }
    }
    String columnExe = "";
    columnExe = "empID,Fname,Lname,Username,Password,Address,Contact,Type";
    String[] colH = columnExe.split(",");
    int colL = 0;
    colL = columnExe.split(",").length;
    headerTable = new PdfPTable(colL);
    for (int x = 0; x < colL; x++) {
        if (colH[x].toString().equals(col1)) {
            colH[x] = "OrderNo1";
        } else if (colH[x].toString().equals(col2)) {
            colH[x] = "O.CustNo";
        }

        PdfPCell newHeader = new PdfPCell();
        newHeader.addElement(new Paragraph(colH[x]));
        headerTable.addCell(newHeader);
    }
    int colNums = colH.length;
    int colCount = 0;
    for (int x = 1; x <= colL; x++) {
        colCount += 1;

        PdfPCell newCell = new PdfPCell();
        newCell.addElement(new Paragraph((x)));
        headerTable.setWidthPercentage(90);
        headerTable.addCell(newCell);
    }
    float[] widths2 = new float[colNums];
    for (int i = 0; i < colNums; i++) {
        widths2[i] = 150;
    }
    try {
        headerTable.setWidths(widths2);
    } catch (DocumentException ex) {
        Logger.getLogger(PDFEmployees.class.getName()).log(Level.SEVERE, null, ex);
    }

    return headerTable;
}

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

private void addBodyAndAttachments(PdfWriter pdfWriter, Document document, PdfPTable bodyTable, String body,
        Collection<Part> attachments) throws DocumentException, MessagingException, IOException {
    /*//from w w  w  .j a va 2  s .  c  o m
     * Font for anchors (links)
     */
    Font linkFont = createLinkFont();

    FontSelector bodyFontSelector = createBodyFontSelector();

    PdfPCell bodyCell = new PdfPCell();

    /*
     * Body table will be white
     */
    bodyCell.setGrayFill(1f);

    bodyCell.setPadding(10);

    Phrase bodyPhrase = new Phrase();

    bodyCell.setPhrase(bodyPhrase);

    /*
     * Matcher we need to convert links to clickable links
     */
    Matcher urlMatcher = urlPattern.matcher(body);

    String textPart;

    int currentIndex = 0;

    /*
     * Add body and links 
     */
    while (urlMatcher.find()) {
        textPart = body.substring(currentIndex, urlMatcher.start());

        addTextPart(textPart, bodyPhrase, bodyFontSelector);

        String linkPart = urlMatcher.group();

        if (linkPart != null) {
            addLinkPart(linkPart, bodyPhrase, linkFont);

            currentIndex = urlMatcher.start() + linkPart.length();
        }
    }

    textPart = body.substring(currentIndex);

    addTextPart(textPart, bodyPhrase, bodyFontSelector);

    bodyTable.addCell(bodyCell);

    document.add(bodyTable);

    addAttachments(pdfWriter, attachments);
}