Example usage for com.itextpdf.text.pdf PdfPCell setBackgroundColor

List of usage examples for com.itextpdf.text.pdf PdfPCell setBackgroundColor

Introduction

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

Prototype


public void setBackgroundColor(final BaseColor backgroundColor) 

Source Link

Document

Sets the backgroundcolor of the rectangle.

Usage

From source file:net.yuvideo.voipRacuni.classes.PrintPageListing.java

public void createListing() {

    document.open();//  www. j  ava  2  s  .  c  om
    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);

    //HEADERS
    PdfPCell cell = new PdfPCell(new Phrase("IZVETAJ-LISTING", fontBold));
    cell.setColspan(5);
    cell.setBorder(0);
    table.addCell(cell);

    //HEADER KORISNIK
    String korisnik;
    if (user.isFirma()) {
        korisnik = user.getNazivFirme();
    } else {
        korisnik = user.getIme();
    }
    cell = new PdfPCell(
            new Phrase(String.format("%s - %s - %s", korisnik, user.getBrojTelefona(), this.period), font));

    cell.setColspan(5);
    cell.setBorder(0);
    table.addCell(cell);

    //HEADER TABLE
    PdfPCell cellH1 = new PdfPCell(new Phrase("br.", fontBold));
    cellH1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(cellH1).setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellH2 = new PdfPCell(new Phrase("Pozivani broj", fontBold));
    cellH2.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(cellH2).setHorizontalAlignment(1);

    PdfPCell cellH3 = new PdfPCell(new Phrase("Destinacija", fontBold));
    cellH3.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(cellH3).setHorizontalAlignment(1);

    PdfPCell cellH4 = new PdfPCell(new Phrase("Vreme", fontBold));
    cellH4.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(cellH4).setHorizontalAlignment(1);

    PdfPCell cellH5 = new PdfPCell(new Phrase("Trajanje poziva", fontBold));
    cellH5.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(cellH5).setHorizontalAlignment(1);

    PdfPCell cellIzvestaj;
    int ukupno = 0;

    for (izvestajPotrosnje izvestaj : listing) {
        //potrosnja ukupno

        //Redni broj
        cellIzvestaj = new PdfPCell(new Phrase(String.valueOf(izvestaj.br), font));
        cellIzvestaj.setHorizontalAlignment(1);
        cellIzvestaj.setVerticalAlignment(5);
        table.addCell(cellIzvestaj);

        //Pozivani broj
        cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getSource(), font));
        cellIzvestaj.setHorizontalAlignment(1);
        cellIzvestaj.setVerticalAlignment(5);
        table.addCell(cellIzvestaj);

        //Destinacija
        cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getDestination(), font));
        cellIzvestaj.setHorizontalAlignment(1);
        cellIzvestaj.setVerticalAlignment(5);
        table.addCell(cellIzvestaj);

        //Vreme
        cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getDatumPoziva(), font));
        cellIzvestaj.setHorizontalAlignment(1);
        cellIzvestaj.setVerticalAlignment(5);
        table.addCell(cellIzvestaj);

        //trajanje poziva
        cellIzvestaj = new PdfPCell(new Phrase(izvestaj.getTrajanje(), font));
        cellIzvestaj.setHorizontalAlignment(1);
        cellIzvestaj.setVerticalAlignment(5);
        table.addCell(cellIzvestaj);

        ukupno = izvestaj.getUkupno_poziv();
    }

    PdfPCell footer = new PdfPCell(new Phrase(
            String.format("Ukupno: %s", LocalTime.MIN.plusSeconds(ukupno).toString()), fontLargeBold));
    footer.setColspan(5);
    footer.setHorizontalAlignment(2);
    footer.setBorder(0);
    table.addCell(footer);

    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(PrintPageListing.class.getName()).log(Level.SEVERE, null, ex);
    }

    document.close();

}

From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java

License:Apache License

/**
 * Create the metrics values table for given report unit. This table will be added to the PDF document.
 *
 * @param allMetricsMap map of all QC metrics - keys and description.
 * @param reportUnit    Report unit for which to create the metrics values table.
 * @return PDF table containing metrics values of the report unit.
 *//*w  w w  . ja  v  a 2s.c om*/
private static PdfPTable createMetricsValuesTable(final Map<String, String> allMetricsMap,
        final ReportUnit reportUnit) {
    /*
     * TODO: Column size, font size and spacing of the metrics value table. 
     */
    // Create columns names.
    final String columnNames[] = { Constants.METRICS_ID_COLUMN_NAME, Constants.DESCRIPTION_COLUMN_NAME,
            Constants.VALUE_COLUMN_NAME, Constants.METRICS_ID_COLUMN_NAME, Constants.DESCRIPTION_COLUMN_NAME,
            Constants.VALUE_COLUMN_NAME, };
    //Creation of table object.
    final PdfPTable table = new PdfPTable(columnNames.length);
    try {
        table.setSpacingBefore(TABLE_SPACING);
        //Set the table width. 
        table.setTotalWidth(COLUMN_WIDTHS);
        table.setLockedWidth(true);
        //Add table header. 
        for (int i = 0; i < TOTAL_COLUMNS; ++i) {
            final PdfPCell headerCell = new PdfPCell(new Phrase(columnNames[i], Constants.TABLE_HEADER_FONT));
            headerCell.setBackgroundColor(BaseColor.RED);
            headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(headerCell);
        }
        //Read metricsValues corresponding to reportUnit.
        final Map<String, String> metricsValues = reportUnit.getMetricsValues();
        //TODO: Split allMetricsMap in two parts such that sorted rows are properly added in the table.
        //Get all keys  
        final Object[] keyArray = allMetricsMap.keySet().toArray();
        //get all values
        final Object[] valueArray = allMetricsMap.values().toArray();
        //Calculate halfSize
        final int halfSize = keyArray.length / 2;
        for (int i = 0; i < halfSize; ++i) {
            addMetric(keyArray[i].toString(), valueArray[i].toString(), metricsValues, table);
            addMetric(keyArray[i + halfSize].toString(), valueArray[i + halfSize].toString(), metricsValues,
                    table);
        }
    } catch (final DocumentException e) {
        //DocumentException signals that an error has occurred in a Document.
        logger.log(Level.SEVERE, String.format(PDF_TABLE_EXCEPTION_MESSAGE, reportUnit.getMsrunName()), e);
    }
    return table;
}

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

private void designTableTitleCell(PdfPTable table, String str) {
    PdfPCell cell;
    // we add a c with colspan 3
    cell = new PdfPCell(new Phrase(str, BLUE_NORMAL));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.ORANGE);
    cell.setColspan(14);//ww  w .  j av a  2s .c  o  m
    table.addCell(cell);
}

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

private void designRowTitleCell(PdfPTable table, String str) {
    PdfPCell cell;
    // we add a c with colspan 3
    cell = new PdfPCell(new Phrase(str, BLUE_NORMAL));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.ORANGE);
    //cell.setColspan(14);
    table.addCell(cell);/*  w ww . j a  v  a  2  s.com*/
}

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

private void designTableHeaderRowCell(PdfPTable table, String str) {
    PdfPCell cell;
    // we add a c with colspan 3
    cell = new PdfPCell(new Phrase(str, BLUE_NORMAL));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.ORANGE);
    //cell.setColspan(14);
    table.addCell(cell);//w w  w.j  ava  2 s.  c  o m
}

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

private void designDataCell(PdfPTable table, String str) {
    PdfPCell cell;
    // we add a c with colspan 3
    cell = new PdfPCell(new Phrase(str, BLACK_NORMAL));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.CYAN);
    //cell.setColspan(14);
    table.addCell(cell);//from w  ww  .  ja  v a 2s  . co m
}

From source file:org.apache.jmeter.visualizers.CreateReport.java

License:Apache License

/**
 * Creates a table; widths are set with setWidths().
 * @return a PdfPTable//  w ww. jav  a 2 s. com
 * @throws DocumentException
 */
public PdfPTable createTable1() throws DocumentException {
    PdfPTable table = new PdfPTable(7);

    table.setWidthPercentage(570 / 5.23f);
    table.setWidths(new int[] { 4, 4, 3, 3, 3, 3, 5 });
    PdfPCell cell = null;
    for (int k = 0; k < 10; k++) {
        if (k != 5 && k != 8 && k != 9) {
            cell = new PdfPCell(new Phrase(JMeterUtils.getResString(COLUMNS[k]), headerFont));
            BaseColor BC = new BaseColor(164, 188, 196);
            cell.setBackgroundColor(BC);
            cell.setColspan(1);
            table.addCell(cell);
        }
    }

    for (int l = 0; l < model.getRowCount(); l++) //row count does not include table headers
        for (int k = 0; k < 10; k++) {
            if (k != 5 && k != 8 && k != 9) {
                cell = new PdfPCell(new Phrase(model.getValueAt(l, k).toString(), rowFont));
                cell.setGrayFill(2);
                table.addCell(cell);
            }
        }
    return table;

    /* original basic statements
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(288 / 5.23f);
    table.setWidths(new int[]{2, 1, 1});
    PdfPCell cell;
    cell = new PdfPCell(new Phrase("Table 1"));
    cell.setColspan(3);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("Cell with rowspan 2"));
    cell.setRowspan(2);
    table.addCell(cell);
    table.addCell("row 1; cell 1");
    table.addCell("row 1; cell 2");
    table.addCell("row 2; cell 1");
    table.addCell("row 2; cell 2");
    return table;
    */
}

From source file:org.apache.jmeter.visualizers.CreateReport.java

License:Apache License

public PdfPTable createTable2() throws DocumentException {
    PdfPTable table = new PdfPTable(4);

    table.setWidthPercentage(570 / 5.23f);
    table.setWidths(new int[] { 1, 2, 1, 3 });
    PdfPCell cell = null;
    for (int k = 0; k < 4; k++) {
        {// w w  w .  ja  v a2  s .c  o  m
            cell = new PdfPCell(new Phrase(model2.getColumnName(k), headerFont));
            BaseColor BC = new BaseColor(164, 188, 196);
            cell.setBackgroundColor(BC);
            cell.setColspan(1);
            table.addCell(cell);
        }
    }

    for (int l = 0; l < model2.getRowCount(); l++) //row count does not include table headers
        for (int k = 0; k < 4; k++) {

            cell = new PdfPCell(new Phrase(model2.getValueAt(l, k).toString(), rowFont));
            cell.setGrayFill(2);
            table.addCell(cell);

        }
    return table;
}

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);/* ww w  .  ja v a2 s.c  o  m*/
    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.cejug.yougi.web.report.EventAttendeeReport.java

License:Open Source License

public void printReport(List<Attendee> attendees) throws DocumentException {
    float[] columnSizes = { 20, 220, 220, 60 };
    PdfPTable table = new PdfPTable(columnSizes.length);
    table.setLockedWidth(true);/*from   w ww .j a  va2s.  co  m*/
    table.setTotalWidth(columnSizes);

    PdfPCell headerCell = new PdfPCell(new Phrase("Yougi"));
    headerCell.setColspan(4);
    headerCell.setBackgroundColor(BaseColor.ORANGE);
    headerCell.setPadding(3);
    table.addCell(headerCell);

    table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);

    PdfPCell checkCell = new PdfPCell(new Phrase(" "));
    checkCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(checkCell);

    PdfPCell productCell = new PdfPCell(new Phrase("Nome"));
    productCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    productCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(productCell);

    PdfPCell currentPurchaseCell = new PdfPCell(new Phrase("Email"));
    currentPurchaseCell.setPadding(3);
    currentPurchaseCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    currentPurchaseCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(currentPurchaseCell);

    PdfPCell previousPurchaseCell = new PdfPCell(new Phrase("Presente"));
    previousPurchaseCell.setPadding(3);
    previousPurchaseCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    previousPurchaseCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(previousPurchaseCell);

    table.getDefaultCell().setBackgroundColor(null);
    table.setHeaderRows(2);

    Font font = new Font(Font.FontFamily.HELVETICA, 9);
    int seq = 1;
    for (Attendee attendee : attendees) {
        table.addCell(new Phrase(String.valueOf(seq++), font));

        table.addCell(new Phrase(attendee.getUserAccount().getFullName(), font));

        table.addCell(new Phrase(attendee.getUserAccount().getEmail(), font));

        table.addCell(" ");
    }

    document.add(table);
}