Example usage for com.itextpdf.text.pdf PdfPTable addCell

List of usage examples for com.itextpdf.text.pdf PdfPTable addCell

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable addCell.

Prototype

public void addCell(final Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

From source file:be.rheynaerde.poolsheets.ClubPoolSheet.java

License:Open Source License

@Override
protected void buildTable(Document document) throws DocumentException {
    int columnCount = configuration.getNrOfPlayers() + configuration.getSummaryColumnCount() + 3;
    int nameCellWidth = 5;

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setTotalWidth(//from   www.  j av  a  2s.  c  o m
            (configuration.getNrOfPlayers() + 1 + nameCellWidth + 0.1f + configuration.getSummaryColumnCount())
                    * configuration.getSquareCellSize());
    table.setLockedWidth(true);
    float[] widths = new float[columnCount];
    widths[0] = 1f * nameCellWidth;
    for (int i = 1; i < widths.length; i++) {
        widths[i] = 1f;
    }
    widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f;
    table.setWidths(widths);

    PdfPCell cell = new PdfPCell(new Paragraph(configuration.getTitle(), configuration.getTitleFont()));
    cell.setColspan(columnCount);
    cell.setPaddingBottom(configuration.getSquareCellSize() / 2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    {
        table.addCell(getHeaderCell(bundle.getString("name")));
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int i = 0; i < configuration.getSummaryColumnCount(); i++) {
            table.addCell(getHeaderCell(configuration.getSummaryColumnName(i)));
        }
    }

    for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
        table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1));
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < i; j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result));
            resultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(resultCell);
        }
        table.addCell(getSolidCell());
        for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result));
            resultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(resultCell);
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int j = 0; j < configuration.getSummaryColumnCount(); j++) {
            String result = configuration.getSummaryColumnValue(i + 1, j);
            PdfPCell summaryCell = new PdfPCell(new Phrase(result == null ? "" : result));
            summaryCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            summaryCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(summaryCell);
        }
    }

    document.add(table);
}

From source file:be.rheynaerde.poolsheets.PufCompletePoolSheet.java

License:Open Source License

@Override
protected PdfPTable getScoreTable() throws DocumentException {
    final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2;
    //one column for each player, an extra column for the numbers and a column for the team marks

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setTotalWidth((columnCount) * configuration.getSquareCellSize());
    table.setLockedWidth(true);//w  w  w  .j a  v  a  2s  . c  o  m
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;
    }
    table.setWidths(widths);

    PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2);
    topCell.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(topCell);
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1)));
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2)));

    table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1));
    {
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) {
        if (i == configuration.getNrOfPlayers(1))
            table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM,
                    configuration.getNrOfPlayers(2), 1));

        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); j++) {
            if (i == j) {
                PdfPCell blackCell = getSolidCell();
                table.addCell(blackCell);
            } else {
                table.addCell(configuration.getResult(i, j));
            }
        }
    }

    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return table;
}

From source file:be.rheynaerde.poolsheets.PufSingleTeamPoolSheet.java

License:Open Source License

@Override
protected PdfPTable getScoreTable() throws DocumentException {
    final int columnCount = configuration.getNrOfPlayers() + 2;

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setTotalWidth((columnCount) * configuration.getSquareCellSize());
    table.setLockedWidth(true);/*from   ww  w.  j  a v  a2  s  .  com*/
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;
    }
    table.setWidths(widths);

    PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2);
    topCell.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(topCell);
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers()));

    table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1));
    {
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < configuration.getNrOfPlayers(); j++) {
            if (i == j) {
                PdfPCell blackCell = getSolidCell();
                table.addCell(blackCell);
            } else {
                table.addCell(configuration.getResult(i, j));
            }
        }
    }

    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return table;
}

From source file:be.rheynaerde.poolsheets.PufTeamPoolSheet.java

License:Open Source License

protected PdfPTable getScoreTable() throws DocumentException {
    //table for scores
    final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2;
    //one column for each player, an extra column for the numbers and a column for the team marks

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.setTotalWidth((columnCount) * configuration.getSquareCellSize());
    table.setLockedWidth(true);//from   ww w  . j  a va 2s . c o m
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;
    }
    table.setWidths(widths);

    PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2);
    topCell.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(topCell);
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1)));
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2)));

    table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1));
    {
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(1); i++) {
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        if (i == 0) {
            PdfPCell blackCell = getSolidCell();
            blackCell.setColspan(configuration.getNrOfPlayers(1));
            blackCell.setRowspan(configuration.getNrOfPlayers(1));
            table.addCell(blackCell);
        }
        for (int j = 0; j < configuration.getNrOfPlayers(2); j++) {
            table.addCell(configuration.getResult(0, i, 1, j));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(2), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(2); i++) {
        table.addCell(getHeaderCell(Integer.toString(configuration.getNrOfPlayers(1) + i + 1)));
        for (int j = 0; j < configuration.getNrOfPlayers(1); j++) {
            table.addCell(configuration.getResult(1, i, 0, j));
        }
        if (i == 0) {
            PdfPCell blackCell = getSolidCell();
            blackCell.setColspan(configuration.getNrOfPlayers(2));
            blackCell.setRowspan(configuration.getNrOfPlayers(2));
            table.addCell(blackCell);
        }
    }
    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return table;
}

From source file:be.rheynaerde.poolsheets.StandardPoolSheet.java

License:Open Source License

protected void buildTable(Document document) throws DocumentException {
    int columnCount = 1 + 1 + configuration.getNrOfPlayers() + 1 + configuration.getSummaryColumnCount();
    // name + number + scores + spacer 
    //    + summary
    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);

    table.setTotalWidth((configuration.getNrOfPlayers() + 7 //the name column + extra space between grid and summary
                                                            //currently the name column just gets a width that is
                                                            //a multiple of the width of the other cells. Better
                                                            //would be to let this cell take up the remaining space.
            + configuration.getSummaryColumnCount()) * configuration.getSquareCellSize());
    table.setLockedWidth(true);/*from ww w  .j  a  va2 s . co  m*/
    float[] widths = new float[columnCount];
    widths[0] = 5f;
    for (int i = 1; i < widths.length; i++) {
        widths[i] = 1f;
    }
    widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f;
    table.setWidths(widths);

    {
        table.addCell(getHeaderCell(bundle.getString("name")));
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int i = 0; i < configuration.getSummaryColumnCount(); i++) {
            table.addCell(getHeaderCell(configuration.getSummaryColumnName(i)));
        }
    }

    for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
        table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1));
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < i; j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }
        table.addCell(getSolidCell());
        for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int j = 0; j < configuration.getSummaryColumnCount(); j++) {
            String result = configuration.getSummaryColumnValue(i + 1, j);
            PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }
    }
    document.add(table);
}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private PdfPTable createModelPage(Contact contact, Model model, PdfWriter pdfWriter)
        throws IOException, DocumentException {

    final PdfPTable pdfPTable = new PdfPTable(new float[] { 40f, 1f, 59f });
    pdfPTable.setTotalWidth(iTextUtil.PAGE_SIZE.getWidth());
    pdfPTable.addCell(cell(buildModelDetailSection(model, pdfWriter)));
    pdfPTable.addCell(cell(new Paragraph()));
    pdfPTable.addCell(cell(buildModelPricingTables(contact, model)));
    return pdfPTable;

}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private PdfPTable buildModelPricingTables(Contact contact, Model model) {

    final PdfPTable table = new PdfPTable(1);

    final List<Pricing> validPricings = model.validPricings(contact);

    if (CollectionUtils.isEmpty(validPricings)) {
        final Chunk chunk = new Chunk("Contact us for pricing on this model", iTextUtil.getFontContactUs());
        chunk.setAction(new PdfAction(contactUsUrl));
        table.addCell(cell(new Phrase(chunk)));
    } else {//from  ww  w  .  j ava2  s  .c o m
        for (Pricing pricing : validPricings) {
            table.addCell(cell(buildModelPricingTable(pricing)));
        }
    }

    return table;

}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private PdfPTable buildModelPricingTable(Pricing pricing) {
    final PdfPTable pricingTable = new PdfPTable(pricing.getNumberOfHeaderItems());

    pricingTable.addCell(cell(new Paragraph(pricing.getCategory(), iTextUtil.getFontModelCategory()),
            pricing.getNumberOfHeaderItems()));
    pricingTable.addCell(cell(new Paragraph(" "), pricing.getNumberOfHeaderItems()));

    if (pricing.isQuantities()) {
        pricingTable.addCell(cellH(new Paragraph("Quantity", iTextUtil.getFontModelPricingTitle())));
    }//  ww w . ja  va  2  s.c o m
    if (pricing.isAge()) {
        pricingTable.addCell(cellH(new Paragraph("Age (weeks)", iTextUtil.getFontModelPricingTitle())));
    }
    if (pricing.isMale()) {
        pricingTable.addCell(cellH(new Paragraph("Male", iTextUtil.getFontModelPricingTitle())));
    }
    if (pricing.isFemale()) {
        pricingTable.addCell(cellH(new Paragraph("Female", iTextUtil.getFontModelPricingTitle())));
    }
    boolean invert = false;
    for (Line line : pricing.getLines()) {
        if (pricing.isQuantities()) {
            pricingTable.addCell(
                    cellD(new Paragraph(line.getQuantity(), iTextUtil.getFontModelPricingData()), invert));
        }
        if (pricing.isAge()) {
            pricingTable
                    .addCell(cellD(new Paragraph(line.getAge(), iTextUtil.getFontModelPricingData()), invert));
        }
        if (pricing.isMale()) {
            pricingTable
                    .addCell(cellD(new Paragraph(line.getMale(), iTextUtil.getFontModelPricingData()), invert));
        }
        if (pricing.isFemale()) {
            pricingTable.addCell(
                    cellD(new Paragraph(line.getFemale(), iTextUtil.getFontModelPricingData()), invert));
        }
        invert = !invert;
    }

    if (!StringUtils.isEmpty(pricing.getMessage())) {
        pricingTable.addCell(cell(new Paragraph(pricing.getMessage(), iTextUtil.getFontModelPricingMessage()),
                pricing.getNumberOfHeaderItems()));
    }
    pricingTable.addCell(cell(new Paragraph(" "), pricing.getNumberOfHeaderItems()));

    return pricingTable;
}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private PdfPTable buildModelDetailSection(Model model, PdfWriter pdfWriter)
        throws IOException, BadElementException {

    final Phrase p = processHtmlCodes(model.getProductNameProcessed(), iTextUtil.getFontModelTitle(),
            iTextUtil.getFontModelSymbol());
    for (Chunk c : p.getChunks()) {
        c.setAction(new PdfAction(model.getUrl()));
    }/*from w  w w  . ja  va 2  s.  com*/

    final StringBuilder strAppList = new StringBuilder();
    for (String application : model.getApplicationsSorted()) {
        if (strAppList.length() != 0) {
            strAppList.append(", ");
        }
        strAppList.append(application);
    }

    final PdfPTable table = new PdfPTable(1);

    table.addCell(cell(p));

    table.addCell(createRow("Model Number", model.getModelNumber(), null));
    table.addCell(createRow("Animal Type", model.getAnimalType(), null));
    table.addCell(createRow("Nomenclature", model.getNomenclatureParsed(), null));
    table.addCell(createRow("Application(s)", strAppList.toString(), null));
    table.addCell(createRow("Health Report", model.getHealthReport(), model.getHealthReport()));
    table.addCell(createRow("Species", model.getSpecies(), null));

    table.addCell(cell(createOrderButton(model)));

    return table;

}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private PdfPTable createOrderButton(Model model) throws IOException, BadElementException {

    final Chunk chunk = new Chunk("Order on taconic.com", iTextUtil.getFontButton());
    chunk.setAction(/*from  www .  j  ava2 s  .c  om*/
            new PdfAction("http://www.taconic.com/start-an-order?modelNumber=" + model.getModelNumber()));

    final PdfPCell cell = cell(new Phrase(chunk));
    cell.setBackgroundColor(iTextUtil.getTaconicRed());
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(8);

    final PdfPTable button = new PdfPTable(new float[] { 80f, 20f });
    button.addCell(cell(new Phrase(" "), 2));
    button.addCell(cell);
    button.addCell(cell(new Phrase(" ")));
    button.addCell(cell(new Phrase(" "), 2));

    return button;
}