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

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

Introduction

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

Prototype


public void setBackgroundColor(Color backgroundColor) 

Source Link

Document

Sets the backgroundcolor of the rectangle.

Usage

From source file:rollyroll.com.servlet.ModuloServlet.java

private void exportar_ModulosaPDF(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    try {//from  w  w w .j  a v  a  2s .  c  om
        //            String[] headers = new String[]{"CODIGO", "NOMBRE", "ACCION", "ORDEN", "ICONO", "ESTADO"};
        String[] headers = new String[] { "NOMBRE", "ACCION", "ICONO" };

        ArrayList<Modulo> lista = null;
        lista = moduloService.listar_Modulos();

        PdfPTable table = new PdfPTable(headers.length);
        table.setHorizontalAlignment(0);
        table.setWidthPercentage(95);
        float[] espaciocolumna = new float[] { 25f, 38f, 50f };
        table.setWidths(espaciocolumna);
        for (int i = 0; i < headers.length; i++) {
            String header = headers[i];
            PdfPCell cell = new PdfPCell();
            cell.setBackgroundColor(Color.YELLOW);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setPhrase(new Phrase(header.toUpperCase(), new Font(Font.HELVETICA, 10, Font.BOLD)));
            table.addCell(cell);
        }
        table.completeRow();
        PdfPCell cell;

        //            int codigomodulo = 0;
        String nombremodulo = "";
        String accionmodulo = "";
        //            int ordenmodulo = 0;
        String iconomodulo = "";
        //            int estadomodulo = 0;

        for (Modulo modulo : lista) {
            //                codigomodulo += Integer.parseInt(modulo.getCodigomodulo());
            nombremodulo += modulo.getNombremodulo();
            accionmodulo += modulo.getAccionmodulo();
            //                ordenmodulo += Integer.parseInt(modulo.getOrdenmoduloS());
            iconomodulo += modulo.getIconomodulo();
            //                estadomodulo += Byte.parseByte(modulo.getEstadomoduloS());

            //                cell = new PdfPCell();
            //                cell.setPhrase(new Phrase(modulo.getCodigomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            //                cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            //                table.addCell(cell);
            //                
            cell = new PdfPCell();
            cell.setPhrase(new Phrase(modulo.getNombremodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            table.addCell(cell);

            cell = new PdfPCell();
            cell.setPhrase(new Phrase(modulo.getAccionmodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            table.addCell(cell);

            //                cell = new PdfPCell();
            //                cell.setPhrase(new Phrase(modulo.getOrdenmoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            //                cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            //                table.addCell(cell);
            cell = new PdfPCell();
            cell.setPhrase(new Phrase(modulo.getIconomodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            table.addCell(cell);

            //                cell = new PdfPCell();
            //                cell.setPhrase(new Phrase(modulo.getEstadomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            //                cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            //                table.addCell(cell);
        }

        table.completeRow();

        //incia diseo de documento exportado
        Document document = new Document(PageSize.A4.rotate(), 20, 5, 5, 5);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();

        document.addTitle("Reporte de Ventas Generales");
        document.add(
                new Paragraph("Reporte: Ventas Generales 2016", new Font(Font.HELVETICA, 16, Font.UNDERLINE)));
        document.add(new Paragraph("_"));
        document.add(table);
        document.add(Chunk.NEWLINE);
        document.add(new Paragraph(
                "Leyenda: AB: Inicio, BA: Retorno (Importante: No se consideran unidades sin GPS)"));
        document.addAuthor("Quispe Roque Alex Christian");

        table = new PdfPTable(4);
        table.setHorizontalAlignment(0);
        table.setWidthPercentage(40);
        espaciocolumna = new float[] { 10f, 40f, 20f, 20f };
        table.setWidths(espaciocolumna);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setPhrase(new Phrase("RESUMEN", new Font(Font.HELVETICA, 10, Font.BOLD)));
        cell.setColspan(7);
        table.addCell(cell);
        table.completeRow();

        //aqui iniciamos asignacion de datos
        //===================================================================
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setBackgroundColor(Color.yellow);
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("FLOTA OPERATIVA", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase(lista.size() + "", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("UNIDADES", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //            table.completeRow();
        //
        //            //==================================================================================
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("2", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setBackgroundColor(Color.yellow);
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("NRO DE VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase((totalAB + totalBA) + "", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            table.completeRow();
        //==================================================================================
        document.add(Chunk.NEWLINE);
        document.add(table);

        document.left(1);
        document.top(1);
        document.close();
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        //            response.setHeader("Content-Disposition", "attachment; filename=ReporteGeneraldeModulos.pdf");
        response.setHeader("Content-Disposition", "filename=ReporteGeneraldeModulos.pdf");
        response.setHeader("Pragma", "public");
        response.setContentType("application/pdf");
        response.setContentLength(baos.size());
        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        out.flush();

    } catch (Exception e) {
        RequestDispatcher rd2;
        rd2 = request.getRequestDispatcher("vista/include/error_404.jsp");
        rd2.forward(request, response);
        System.out.println(
                "rollyroll.com.servlet.ModuloServlet.exportar_ModulosaPDF() => ERROR GRAVE AL GENERAR PDF");
        e.getMessage();
    }
}

From source file:sms.ViewResults.java

private void itextPrint() {
    //  String searchQuery = "SELECT * FROM `exam` WHERE `yearid` ='" + yearid + "'AND `termid`='"+termid+"'AND `examid`='"+yearid+"'"
    //          + "AND CONCAT(`class`) LIKE '%" + stream + "%'AND YEAR(updated_at)='"+yearchooser.getYear()+"'";

    methods nn = new methods();
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(","));
    chooser.setDialogTitle("Save at");
    chooser.setApproveButtonText("save");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {//from www . j  av  a  2  s. com
            Form1Exams n = new Form1Exams();
            Document pdfp = new Document();
            PdfWriter.getInstance(pdfp,
                    new FileOutputStream(new File(chooser.getSelectedFile(), "report.pdf")));
            pdfp.open();
            Paragraph p = new Paragraph();
            p.setAlignment(Element.ALIGN_CENTER);
            p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD));
            Paragraph po = new Paragraph();
            po.setAlignment(Element.ALIGN_CENTER);
            po.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD));

            Paragraph pd = new Paragraph();
            pd.setAlignment(Element.ALIGN_CENTER);
            pd.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 14, Font.BOLD));
            p.add("ITHANGA SECONDARY SCHOOL");
            po.add("PO.BOX 238  ITHANGA THIKA");
            pd.add(new Date().toString());
            pdfp.add(p);
            pdfp.add(po);
            pdfp.add(pd);

            pdfp.add(new Paragraph("\n.................................................................."
                    + ".................................................................................\n"));
            String[] names = n.findSubjectname();
            PdfPTable tbl = new PdfPTable(names.length + 6);
            tbl.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
            // tbl.setWidthPercentage(100);
            tbl.setTotalWidth(575);
            tbl.setLockedWidth(true);
            PdfPTable tbl1 = new PdfPTable(names.length + 6);
            tbl1.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
            // tbl.setWidthPercentage(100);
            tbl1.setTotalWidth(575);
            tbl1.setLockedWidth(true);
            PdfPCell cell = new PdfPCell(new Paragraph("RESULTS"));
            cell.setColspan((names.length + 4) * 2);
            cell.setBackgroundColor(Color.CYAN);
            tbl1.addCell(cell);
            tbl1.addCell("Pos");
            tbl1.addCell("id");
            tbl1.addCell("Name");
            int a;

            for (a = 0; a < names.length; a++) {
                String s = names[a];
                tbl1.addCell(s.substring(0, Math.min(s.length(), 3)));
            }

            tbl1.addCell("Tot");
            tbl1.addCell("Ave");
            tbl1.addCell("Agg");
            pdfp.add(tbl1);

            try {

                String[] Subjects = n.findSubjectid();
                String[] Subjectsnames = n.findSubjectname();
                int subjectCount = Subjects.length;
                ArrayList<ExamDbDataHolder> users = ListUsers(this.sid.getText());

                for (int i = 0; i < users.size(); i++) {
                    tbl.addCell(String.valueOf(i + 1));
                    String id = ((ExamDbDataHolder) users.get(i)).getSid();
                    String nam = nn.getStudentName(id);
                    String name = "Eric";
                    tbl.addCell(id);
                    tbl.addCell(nam);
                    int c = 2;
                    for (int s = 0; s < Subjects.length; s++) {

                        if (Subjects[s].equals("s1")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getMathematics());
                            //  JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics());
                            // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics();
                            c++;
                        } else if (Subjects[s].equals("s2")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getEnglish());
                            //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish();
                            c++;
                        } else if (Subjects[s].equals("s3")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili();
                            c++;
                        } else if (Subjects[s].equals("s4")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getPhysics());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics();
                            c++;
                        } else if (Subjects[s].equals("s5")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getChemistry());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry();
                            c++;
                        } else if (Subjects[s].equals("s6")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getBiology());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getBiology();
                            c++;
                        } else if (Subjects[s].equals("s7")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getHistory());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getHistory();
                            c++;
                        } else if (Subjects[s].equals("s8")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getGeography());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography();
                            c++;
                        } else if (Subjects[s].equals("s9")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getCre());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getCre();
                            c++;
                        } else if (Subjects[s].equals("s10")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getIre());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getIre();
                            c++;
                        } else if (Subjects[s].equals("s11")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getHre());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getHre();
                            c++;
                        } else if (Subjects[s].equals("s12")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture();
                            c++;
                        } else if (Subjects[s].equals("s13")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getHomescience());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience();
                            c++;
                        } else if (Subjects[s].equals("s14")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign();
                            c++;
                        } else if (Subjects[s].equals("s15")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getComputer());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer();
                            c++;

                        } else if (Subjects[s].equals("s16")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getBuilding());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding();
                            c++;
                        } else if (Subjects[s].equals("s17")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork();
                            c++;
                        } else if (Subjects[s].equals("s18")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork();
                            c++;
                        } else if (Subjects[s].equals("s19")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getMusic());
                            //   row[c] = ((ExamDbDataHolder)users.get(i)).getMusic();
                            c++;
                        } else if (Subjects[s].equals("s20")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getFrench());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench();
                            c++;
                        } else if (Subjects[s].equals("s21")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getGerman());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getGerman();
                            c++;
                        } else if (Subjects[s].equals("s22")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getArabic());
                            // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic();
                            c++;
                        } else if (Subjects[s].equals("s23")) {
                            tbl.addCell(((ExamDbDataHolder) users.get(i)).getBusiness());
                            //  row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness();
                            c++;
                        }

                    }

                    int tt = ((ExamDbDataHolder) users.get(i)).getTotal();
                    tbl.addCell(String.valueOf(tt));
                    float g = Float.valueOf(tt) / 11;
                    tbl.addCell(String.format("%.1f", g));
                    String gr = nn.checkGrade(yearid, String.format("%.1f", g));
                    tbl.addCell(gr);

                }
                pdfp.add(tbl);
            } catch (Exception j) {
                j.printStackTrace();
            }

            pdfp.close();

            // Image img=new Image.getInstance("j.png");

        } catch (DocumentException ex) {
            Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:storemanagment.Printing.java

public PdfPCell createTextCellcolor(String text, int c) {
    PdfPCell cell = new PdfPCell();
    if (c % 2 == 0) {

        Paragraph p = new Paragraph();
        cell.setBackgroundColor(Color.CYAN);
        p.add(text);//from w w w.  j a v  a 2s .c  om
        cell.addElement(p);
    } else {
        Paragraph p = new Paragraph();
        //cell.setBackgroundColor(Color.CYAN);
        p.add(text);
        cell.addElement(p);
    }

    return cell;

}

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void addTitle(Document doc, String text)
        throws IOException, BadElementException, DocumentException {
    float[] widths = { 62f, 164f, 62f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);/*  ww w.  j av  a2s  .  c o  m*/
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.setSpacingAfter(10);

    Image image = Image.getInstance("app_title.gif");
    image.scalePercent(70);
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    Paragraph title = new Paragraph(text, FontFactory.getFont("arial", 12, Font.BOLD));
    cell = new PdfPCell(title);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    image = Image.getInstance("title_shot.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    doc.add(table);

    table = new PdfPTable(1);
    table.setWidthPercentage(100);
    cell = new PdfPCell();
    cell.setBackgroundColor(Color.BLACK);
    cell.setFixedHeight(1);
    table.addCell(cell);

    doc.add(table);
}

From source file:tk.diginspect.main.SoOFSignatories.java

private void insertCell(PdfPTable table, String text, int align, int colspan, String color,
        float BorderWidthTop, float BorderWidthBottom) {

    PdfPCell cell = new PdfPCell(new Paragraph(Font.TIMES_ROMAN, text));
    cell.setHorizontalAlignment(align);//from  w w w . ja v  a  2 s  . c  om
    cell.setColspan(colspan);
    cell.setBackgroundColor(WebColors.getRGBColor(color));
    cell.setPadding(5);
    cell.setBorderWidthTop(BorderWidthTop);
    cell.setBorderWidthBottom(BorderWidthBottom);
    table.addCell(cell);
}

From source file:tk.diginspect.main.SoOFSignatories.java

private void insertCell1(PdfPTable table, String text, float borderWidthTop, float borderWidthBottom,
        float fixedHeight) {
    PdfPCell cell = new PdfPCell(new Paragraph(Font.TIMES_ROMAN, text));
    cell.setBackgroundColor(WebColors.getRGBColor("#FFFFFF"));
    cell.setPadding(5);//from w w  w. jav a 2  s . c  o m
    cell.setBorderWidthTop(borderWidthTop);
    cell.setBorderWidthBottom(borderWidthBottom);
    cell.setFixedHeight(fixedHeight);
    table.addCell(cell);
}

From source file:webBoltOns.server.reportWriter.JRivetWriter.java

License:Open Source License

/**
 * <h2><code>buildBlankLine</code></h2>
 * /*from  w w w  .ja v a  2  s  . c om*/
 * <p>
 *  build a 'blank' line     
 * </p>
 */
private void buildBlankLine() throws DocumentException {

    if (++rowCount < pageLength) {
        PdfPCell cell;
        for (int c = 0; c < reportColumns.length; c++) {
            cell = new PdfPCell(
                    new Paragraph(" ", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)));
            cell.setBorder(0);
            cell.setBackgroundColor(totalColor);
            reportBody.addCell(cell);

        }
    }
}

From source file:webBoltOns.server.reportWriter.JRivetWriter.java

License:Open Source License

/**
 * <h2><code>buildDetilLine</code></h2>
 * /* ww w . j  av a 2 s  .c o  m*/
 * <p>
 *  create and print a detail line on the report    
 * </p>
 * 
 * 
 * @param   String [] record - report record to print
 * 
 */
private void buildDetilLine(String[] record) throws DocumentException {
    newpage = isNewPage(++rowCount);
    PdfPCell cell;

    if (record != null) {
        for (int c = 0; c < reportColumns.length; c++) {
            ReportColumn column = (ReportColumn) reportColumns[c];
            String value = " ";

            if (record != null) {
                if (column.getLevelBreak() > 0)
                    value = column.getAccumulator().getPrintValue(newpage);
                else
                    value = record[c];
            }

            cell = new PdfPCell(
                    new Paragraph(value, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)));

            cell.setBorder(0);
            cell.setNoWrap(true);

            cell.setBackgroundColor(detailColor);

            if (column.getAlignment().equals(ReportColumn.LEFT))
                cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
            else if (column.getAlignment().equals(ReportColumn.RIGHT))
                cell.setHorizontalAlignment(Cell.ALIGN_RIGHT);
            else
                cell.setHorizontalAlignment(Cell.ALIGN_CENTER);

            reportBody.addCell(cell);

        }
    }
}

From source file:webBoltOns.server.reportWriter.JRivetWriter.java

License:Open Source License

/**
 * <h2><code>buildTotalLine</code></h2>
 * /*from   w w w.  ja  va 2 s .  c o m*/
 * <p>
 *  Create printed total lines        
 * </p>
 * 
 * @param   String[] record - A report total line
 * 
 */
private void buildTotalLine(String[] record) throws DocumentException {
    ++rowCount;
    PdfPCell cell;

    if (record != null) {
        for (int c = 0; c < reportColumns.length; c++) {
            ReportColumn column = (ReportColumn) reportColumns[c];
            String value = record[c];

            cell = new PdfPCell(
                    new Paragraph(value, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)));

            cell.setBorder(0);
            cell.setNoWrap(true);

            cell.setBackgroundColor(totalColor);

            if (column.getAlignment().equals(ReportColumn.LEFT))
                cell.setHorizontalAlignment(Cell.ALIGN_LEFT);
            else if (column.getAlignment().equals(ReportColumn.RIGHT))
                cell.setHorizontalAlignment(Cell.ALIGN_RIGHT);
            else
                cell.setHorizontalAlignment(Cell.ALIGN_CENTER);

            reportBody.addCell(cell);

        }
    }
}