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:com.skatettoo.reportes.Generador.java

public String generarPDF() throws Exception {
    try {//  w  ww  . java2 s  .c o  m
        String path = FacesContext.getCurrentInstance().getExternalContext().getRealPath("img");
        path = path.substring(0, path.indexOf("\\build"));
        path = path + "\\web\\img\\";
        Document doc = new Document(PageSize.A4, 36, 36, 10, 10);
        PdfPTable tabla = new PdfPTable(4);
        PdfWriter.getInstance(doc, new FileOutputStream(path + "\\archivo\\reporte.pdf\\"));
        doc.open();
        Image img = Image.getInstance(path + "Skatetoo4.png");
        img.scaleAbsolute(40, 40);
        img.setAlignment(Element.ALIGN_LEFT);
        doc.add(img);
        doc.addTitle(this.titulo);
        doc.addAuthor("\n ");
        doc.addAuthor("\n ");
        doc.addAuthor("\n ");
        doc.addAuthor("\n ");
        tabla.setWidthPercentage(100);
        tabla.setWidths(new float[] { 1.4f, 0.8f, 0.8f, 0.8f });
        Object font = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.WHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de tatuadores", (Font) font));
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPaddingTop(0f);
        cell.setPaddingBottom(7f);
        cell.setBackgroundColor(new BaseColor(0, 0, 0));
        cell.setBorder(0);
        cell.setBorderWidthBottom(2f);
        tabla.addCell(cell);
        tabla.addCell("Tatuador");
        tabla.addCell("Cantidad de diseos");
        tabla.addCell("Citas realizadas");
        tabla.addCell("Noticias publicadas");
        for (Usuario u : this.getUsu()) {
            tabla.addCell(u.getNombre() + " " + u.getApellido());
            tabla.addCell(String.valueOf(u.getDisenioList().size()));
            tabla.addCell(String.valueOf(u.getCitaList1().size()));
            tabla.addCell(String.valueOf(u.getNoticiaList().size()));
        }
        doc.add(tabla);
        doc.bottomMargin();
        /* doc.add(new Paragraph("Tatuador mas solicitado"));
         for(Usuario u : this.getUs()){
        doc.add(new Paragraph(u.getNombre() + " " + u.getApellido()));
         }*/
        doc.close();
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext externalContext = context.getExternalContext();

        externalContext.responseReset();
        externalContext.setResponseContentType("application/pdf");
        externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\"");

        FileInputStream inputStream = new FileInputStream(new File(path + "\\archivo\\reporte.pdf\\"));
        OutputStream outputStream = externalContext.getResponseOutputStream();

        byte[] buffer = new byte[1024];
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            outputStream.write(buffer, 0, length);
        }

        inputStream.close();
        context.responseComplete();
    } catch (Exception e) {
        throw e;
    }
    return "";
}

From source file:com.softwaremagico.tm.pdf.complete.elements.BaseElement.java

License:Open Source License

public static PdfPCell getCell(String text, int border, int colspan, int align, BaseColor color, BaseFont font,
        float fontSize) {
    if (text == null) {
        text = "";
    }/*from   w  w  w  . j ava2s. c  o  m*/
    Phrase content = new Phrase(text, new Font(font, fontSize));
    PdfPCell cell = new PdfPCell(content);
    cell.setColspan(colspan);
    cell.setBorderWidth(border);
    cell.setHorizontalAlignment(align);
    cell.setBackgroundColor(color);

    return cell;
}

From source file:com.softwaremagico.tm.pdf.complete.elements.BaseElement.java

License:Open Source License

public static PdfPCell getCell(Paragraph paragraph, int border, int colspan, int align, BaseColor color) {
    PdfPCell cell = new PdfPCell(paragraph);
    cell.setColspan(colspan);//w  w w. ja va2  s.c  o m
    cell.setBorderWidth(border);
    cell.setHorizontalAlignment(align);
    cell.setBackgroundColor(color);

    return cell;
}

From source file:com.softwaremagico.tm.pdf.complete.elements.BaseElement.java

License:Open Source License

protected PdfPCell getCell(String text, int border, int colspan, int align, BaseColor color, String font,
        int fontSize, int fontType) {
    if (text == null) {
        text = "";
    }/*from   ww  w  .  j av a 2 s .  c o  m*/
    Paragraph p = new Paragraph(text, FontFactory.getFont(font, fontSize, fontType));
    PdfPCell cell = new PdfPCell(p);
    cell.setColspan(colspan);
    cell.setBorderWidth(border);
    cell.setHorizontalAlignment(align);
    cell.setBackgroundColor(color);

    return cell;
}

From source file:com.softwaremagico.tm.pdf.complete.elements.BaseElement.java

License:Open Source License

public static PdfPCell createBlackSeparator() {
    PdfPCell cell = new PdfPCell();
    cell.setBackgroundColor(BaseColor.BLACK);
    setCellProperties(cell);/*from   w  ww .  j av a 2  s .c o  m*/
    cell.setMinimumHeight(10f);
    return cell;
}

From source file:com.softwaremagico.tm.pdf.complete.elements.BaseElement.java

License:Open Source License

public static PdfPCell createWhiteSeparator() {
    PdfPCell cell = new PdfPCell();
    cell.setBackgroundColor(BaseColor.WHITE);
    setCellProperties(cell);//  w  ww . ja v a  2  s.c o m
    cell.setMinimumHeight(6f);
    return cell;
}

From source file:com.softwaremagico.tm.pdf.complete.elements.LateralHeaderPdfPTable.java

License:Open Source License

protected PdfPCell createLateralVerticalTitle(String title, int rowspan) {
    Font font = new Font(FadingSunsTheme.getTitleFont(), getTitleFontSize());
    font.setColor(BaseColor.WHITE);/*from  w  ww. j a  v a2 s  .c  o  m*/
    Phrase content = new Phrase(title, font);
    PdfPCell titleCell = new PdfPCell(content);
    titleCell.setPadding(0);
    titleCell.setRowspan(rowspan);
    titleCell.setRotation(90);
    titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    // titleCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    titleCell.setBackgroundColor(BaseColor.BLACK);
    return titleCell;
}

From source file:com.solidmaps.webapp.report.EnableCompanyRequerimentFederalPDF.java

private void insertCellAlteracao(PdfPTable table, String text) {

     if (text == null) {
         text = "";
     }/*  www  .j  av a2s . c o  m*/

     // create a new cell with the specified Text and Font
     PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_HEADER));
     // set the cell alignment
     // in case there is no text and you wan to create an empty row
     if (text.trim().equalsIgnoreCase("")) {
         cell.setMinimumHeight(10f);
     }

     cell.setHorizontalAlignment(Element.ALIGN_CENTER);
     cell.setColspan(2);
     cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
     cell.setBorderWidth(2);
     cell.setPadding(3f);

     // add the call to the table
     table.addCell(cell);
 }

From source file:com.solidmaps.webapp.report.EnableCompanyRequerimentFederalPDF.java

private void insertHeaderCell(PdfPTable table, String text, Integer colSpan) {

     if (text == null) {
         text = "";
     }/*from   ww  w .  j  av  a2 s.co  m*/

     // create a new cell with the specified Text and Font
     PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_HEADER));
     // set the cell alignment
     // in case there is no text and you wan to create an empty row
     if (text.trim().equalsIgnoreCase("")) {
         cell.setMinimumHeight(10f);
     }

     cell.setVerticalAlignment(Element.ALIGN_CENTER);
     cell.setHorizontalAlignment(Element.ALIGN_CENTER);
     cell.setColspan(colSpan);
     cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
     cell.setBorderWidth(2);
     cell.setPadding(3f);

     // add the call to the table
     table.addCell(cell);
 }

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertCellAlteracao(PdfPTable table, String text) {

    if (text == null) {
        text = "";
    }//from w  w w .j  a v a  2 s  . c om

    // create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_HEADER));
    // set the cell alignment
    // in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setColspan(2);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);

    // add the call to the table
    table.addCell(cell);
}