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

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

Introduction

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

Prototype

public PdfPTable(final PdfPTable table) 

Source Link

Document

Constructs a copy of a PdfPTable.

Usage

From source file:com.mim.servlet.ReportGen.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3/*from w w w.j a va2  s  .  c  o  m*/

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    PdfPCell areaValor = new PdfPCell(new Paragraph("concretera"));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                if (historial.getValor() != null) {
                    if (historial.getValor().length() > 0) {
                        PdfPCell paramCell = new PdfPCell();
                        paramCell.setColspan(3);
                        paramCell.addElement(new Paragraph(historial.getParametro()));
                        paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                        paramCell.setPaddingLeft(10);
                        paramCell.setPaddingBottom(10);

                        PdfPCell valueParamCell = new PdfPCell();
                        valueParamCell.setColspan(5);
                        valueParamCell.setPaddingLeft(10);
                        valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                        valueParamCell.addElement(new Paragraph(historial.getValor()));
                        valueParamCell.setPaddingBottom(10);

                        table.addCell(paramCell);
                        table.addCell(valueParamCell);
                    }
                }
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.miraflorescarwash.controller.PdfController.java

private void crearPdfLavadasPendientes(Document doc, List<Lavada> lavadas) {
    Paragraph parrafo;/*from   w w w .j a v a 2  s.c o  m*/
    PdfPTable tabla;
    String txt;
    PdfPCell cell;
    Phrase frase;
    String fuente;
    int i;
    JFreeChart chart;
    int w, h;
    int pos;
    pos = 0;
    w = h = 500;

    fuente = "arial";
    if (lavadas.isEmpty()) {
        return;
    }
    try {
        //

        // Se abre el documento.
        doc.open();

        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        txt = "Lavadas Pendientes";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_CENTER);

        doc.add(parrafo);
        LineSeparator ls = new LineSeparator();
        doc.add(new Chunk(ls));

        tabla = new PdfPTable(3);

        frase = new Phrase("Id", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Fecha", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Placa de Carro", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Modelo de Carro", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Cliente", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        i = 1;

        for (Lavada lavada : lavadas) {

            if (i % 2 == 0) {
                cell = new PdfPCell();
                cell.setBackgroundColor(new BaseColor(244, 119, 119));

                frase = new Phrase(lavada.getId() + "");
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(lavada.getFechaLavado() + "");
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(lavada.getCarro().getPlaca());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(lavada.getCarro().getModelo().getNombre());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(lavada.getCarro().getCliente().getApellidos() + ", "
                        + lavada.getCarro().getCliente().getNombres());
                cell.setPhrase(frase);
                tabla.addCell(cell);

            } else {
                tabla.addCell(lavada.getId() + "");
                tabla.addCell(lavada.getFechaLavado() + "");
                tabla.addCell(lavada.getCarro().getPlaca());
                tabla.addCell(lavada.getCarro().getModelo().getNombre());
                tabla.addCell(lavada.getCarro().getCliente().getApellidos() + ", "
                        + lavada.getCarro().getCliente().getNombres());
            }
            i++;
        }
        doc.add(tabla);

        doc.close();
    } catch (DocumentException ex) {

    }
}

From source file:com.miraflorescarwash.controller.PdfController.java

private void crearPdfCliente(Document doc, Cliente cliente) {
    Paragraph parrafo;/*from  w  w  w.ja v  a2 s . co m*/
    PdfPTable tabla;
    String txt;
    PdfPCell cell;
    Phrase frase;
    String fuente;
    int i;

    fuente = "arial";
    try {
        //

        // Se abre el documento.
        doc.open();

        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        txt = "Cliente: " + cliente.getNombres();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_CENTER);

        doc.add(parrafo);
        LineSeparator ls = new LineSeparator();
        doc.add(new Chunk(ls));

        doc.add(Chunk.NEWLINE);

        txt = "Datos del Cliente";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 20, Font.UNDERLINE, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Id: ";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        txt = cliente.getId() + "";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.NORMAL, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Nombres: ";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        txt = cliente.getNombres();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.NORMAL, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Apellidos: ";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        txt = cliente.getApellidos();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.NORMAL, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Dni: ";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        txt = cliente.getDni();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.NORMAL, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Email: ";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        txt = cliente.getEmail();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.NORMAL, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Telefono: ";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        txt = cliente.getTelefono();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.NORMAL, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Carros:";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        tabla = new PdfPTable(4);
        frase = new Phrase("Id", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Modelo", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Marca", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Placa", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        i = 1;
        for (Carro carro : cliente.getCarros()) {

            if (i % 2 == 0) {
                cell = new PdfPCell();
                cell.setBackgroundColor(new BaseColor(244, 119, 119));

                frase = new Phrase(carro.getId() + "");
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(carro.getModelo().getNombre());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(carro.getMarca());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(carro.getPlaca());
                cell.setPhrase(frase);
                tabla.addCell(cell);
            } else {
                tabla.addCell(carro.getId() + "");
                tabla.addCell(carro.getModelo().getNombre());
                tabla.addCell(carro.getMarca());
                tabla.addCell(carro.getPlaca());
            }
            i++;
        }
        doc.add(tabla);
        doc.close();
    } catch (DocumentException ex) {

    }
}

From source file:com.miraflorescarwash.controller.PdfController.java

private void crearPdfClienteCreditoDisponible(Document doc, List<CreditoDisponibleCliente> reporte) {
    Paragraph parrafo;// w  ww.j a  va  2 s . com
    PdfPTable tabla;
    String txt;
    PdfPCell cell;
    Phrase frase;
    String fuente;
    CreditoDisponibleCliente cliente;
    int i;

    fuente = "arial";
    if (reporte.isEmpty()) {
        return;
    }
    cliente = reporte.get(0);
    try {
        //

        // Se abre el documento.
        doc.open();

        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        txt = "Cliente: " + cliente.getNombres();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_CENTER);

        doc.add(parrafo);
        LineSeparator ls = new LineSeparator();
        doc.add(new Chunk(ls));

        doc.add(Chunk.NEWLINE);

        txt = "Crdito Disponible";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 20, Font.UNDERLINE, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Nombres: ";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        txt = cliente.getNombres();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.NORMAL, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Apellidos: ";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        txt = cliente.getApellidos();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.NORMAL, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Dni: ";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        txt = cliente.getDni();
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.NORMAL, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);

        txt = "Crdito Disponible:";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 14, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);
        doc.add(Chunk.NEWLINE);
        tabla = new PdfPTable(2);

        frase = new Phrase("Modelo", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Lavadas Disponibles", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        i = 1;
        for (CreditoDisponibleCliente cre : reporte) {

            if (i % 2 == 0) {
                cell = new PdfPCell();
                cell.setBackgroundColor(new BaseColor(244, 119, 119));

                frase = new Phrase(cre.getModeloCarro());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(cre.getLavadas());
                cell.setPhrase(frase);
                tabla.addCell(cell);
            } else {
                tabla.addCell(cre.getModeloCarro());
                tabla.addCell(cre.getLavadas() + "");
            }
            i++;
        }
        doc.add(tabla);
        doc.close();
    } catch (DocumentException ex) {

    }
}

From source file:com.miraflorescarwash.controller.PdfController.java

private void crearPdfCombos(Document doc, List<ComboPorModelo> combos) {
    Paragraph parrafo;// w  w  w  .j a  v  a 2 s. co m
    PdfPTable tabla;
    String txt;
    PdfPCell cell;
    Phrase frase;
    String fuente;
    int i;

    fuente = "arial";
    if (combos.isEmpty()) {
        return;
    }
    try {
        //

        // Se abre el documento.
        doc.open();

        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        txt = "Combos";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_CENTER);

        doc.add(parrafo);
        LineSeparator ls = new LineSeparator();
        doc.add(new Chunk(ls));

        doc.add(Chunk.NEWLINE);

        tabla = new PdfPTable(5);

        frase = new Phrase("Id", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Nombre", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Lavadas", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Modelo", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Precio", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        i = 1;

        for (ComboPorModelo combo : combos) {

            if (i % 2 == 0) {
                cell = new PdfPCell();
                cell.setBackgroundColor(new BaseColor(244, 119, 119));

                frase = new Phrase(combo.getId());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(combo.getCombo().getNombre());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(combo.getCombo().getNumeroLavadas());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(combo.getModelo().getNombre());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase("S/. " + combo.getPrecio() + "0");
                cell.setPhrase(frase);
                tabla.addCell(cell);
            } else {
                tabla.addCell(combo.getId() + "");
                tabla.addCell(combo.getCombo().getNombre());
                tabla.addCell(combo.getCombo().getNumeroLavadas() + "");
                tabla.addCell(combo.getModelo().getNombre());
                tabla.addCell("S/. " + combo.getPrecio() + "0");
            }
            i++;
        }
        doc.add(tabla);
        doc.close();
    } catch (DocumentException ex) {

    }
}

From source file:com.miraflorescarwash.controller.PdfController.java

private void crearPdfCombosReporte(Document doc, List<ComboReporte> combos, PdfWriter writer) {
    Paragraph parrafo;/*from  ww  w . ja  v a2s . c  om*/
    PdfPTable tabla;
    String txt;
    PdfPCell cell;
    Phrase frase;
    String fuente;
    int i;
    JFreeChart chart;
    int w, h;
    int pos;
    pos = 0;
    w = h = 500;

    fuente = "arial";
    if (combos.isEmpty()) {
        return;
    }
    try {
        //

        // Se abre el documento.
        doc.open();

        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        txt = "Reporte de Combos";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_CENTER);

        doc.add(parrafo);
        LineSeparator ls = new LineSeparator();
        doc.add(new Chunk(ls));

        tabla = new PdfPTable(3);

        frase = new Phrase("Id", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Nombre", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Dinero Recaudado", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        i = 1;

        for (ComboReporte combo : combos) {

            if (i % 2 == 0) {
                cell = new PdfPCell();
                cell.setBackgroundColor(new BaseColor(244, 119, 119));

                frase = new Phrase(combo.getId() + "");
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(combo.getNombre());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase("S/. " + combo.getCantidad() + "0");
                cell.setPhrase(frase);
                tabla.addCell(cell);

            } else {
                tabla.addCell(combo.getId() + "");
                tabla.addCell(combo.getNombre());
                tabla.addCell("S/. " + combo.getCantidad() + "0");
            }
            i++;
        }
        doc.add(tabla);
        doc.newPage();
        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        chart = comboService.generarChartReporte(combos);

        w = 500;
        h = 500;

        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(w, h);
        Graphics2D g2d = tp.createGraphics(w, h, new DefaultFontMapper());
        Rectangle2D r2d = new Rectangle2D.Double(0, 0, w, h);
        chart.draw(g2d, r2d);
        cb.addTemplate(tp, 50, 250);
        g2d.dispose();
        doc.close();
    } catch (DocumentException ex) {

    }
}

From source file:com.miraflorescarwash.controller.PdfController.java

private void crearPdfClientesFreq(Document doc, List<ClienteReporte> reporteCompras, PdfWriter writer) {
    Paragraph parrafo;/* w w w.  j  a va 2s . c  o  m*/
    PdfPTable tabla;
    String txt;
    PdfPCell cell;
    Phrase frase;
    String fuente;
    JFreeChart chart;
    int i, w, h;

    fuente = "arial";
    if (reporteCompras.isEmpty()) {
        return;
    }
    try {
        //

        // Se abre el documento.
        doc.open();

        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        txt = "Clientes Frecuentes";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_CENTER);

        doc.add(parrafo);
        LineSeparator ls = new LineSeparator();
        doc.add(new Chunk(ls));

        doc.add(Chunk.NEWLINE);

        tabla = new PdfPTable(3);

        frase = new Phrase("Id", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Nombre", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Dinero", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        i = 1;

        for (ClienteReporte clienteReporte : reporteCompras) {

            if (i % 2 == 0) {
                cell = new PdfPCell();
                cell.setBackgroundColor(new BaseColor(244, 119, 119));

                frase = new Phrase(clienteReporte.getId() + "");
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(clienteReporte.getApellido() + " " + clienteReporte.getNombre());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase("S/. " + clienteReporte.getTotal() + "0");
                cell.setPhrase(frase);
                tabla.addCell(cell);

            } else {
                tabla.addCell(clienteReporte.getId() + "");
                tabla.addCell(clienteReporte.getApellido() + " " + clienteReporte.getNombre());
                tabla.addCell("S/. " + clienteReporte.getTotal() + "0");
            }
            i++;
        }
        doc.add(tabla);

        doc.newPage();
        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        chart = clienteService.generarChartReporte(reporteCompras);

        w = 500;
        h = 500;

        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(w, h);
        Graphics2D g2d = tp.createGraphics(w, h, new DefaultFontMapper());
        Rectangle2D r2d = new Rectangle2D.Double(0, 0, w, h);
        chart.draw(g2d, r2d);
        cb.addTemplate(tp, 50, 250);
        g2d.dispose();
        doc.close();
    } catch (DocumentException ex) {

    }
}

From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java

License:Open Source License

public int handle(final User user, final User manager, final ExpenseNote en)
        throws MalformedURLException, IOException, DocumentException {

    log.info("Building list of expenses ...");
    List<Expense> expenses = Expense.list(en);
    log.info("Retrieved " + expenses.size() + " expenses from the datastore");

    log.info("Creating ExpenseNoteDocOutputStream");
    ExpenseNoteDocOutputStream stream = new ExpenseNoteDocOutputStream(en);

    Document document = new Document();
    PdfWriter.getInstance(document, stream);
    document.open();/*from   www  . j  av  a  2  s .c  o  m*/

    document.addTitle("Expense note " + en.id + " of " + user.name);
    document.addSubject("Expense note generated by Rogerthat Enterprise!");
    document.addKeywords("expense note");
    document.addAuthor(user.name);
    document.addCreator("Rogerthat OneApp Enterprise Mobility");

    Paragraph preface = new Paragraph();

    preface.add(new Paragraph("TP Vision expense note", titleFont));
    preface.add(new Paragraph(" "));

    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    Date date = new Date();
    preface.add(new Paragraph("Date: " + dateFormat.format(date)));
    preface.add(new Paragraph("Requestor: " + user.name));
    preface.add(new Paragraph("Approver: " + manager.name));
    preface.add(new Paragraph(" "));

    PdfPTable table = new PdfPTable(7);
    table.setWidthPercentage(110);
    table.setWidths(new int[] { 5, 15, 15, 35, 10, 15, 10 });
    addHeader(table, "Id");
    addHeader(table, "Date");
    addHeader(table, "Nature");
    addHeader(table, "Description");
    addHeader(table, "Account");
    addHeader(table, "Amount");
    addHeader(table, "Voucher");
    table.setHeaderRows(1);

    Collections.sort(expenses, new Comparator<Expense>() {
        @Override
        public int compare(Expense e1, Expense e2) {
            return (int) (e1.date - e2.date);
        }
    });
    int i = 0;
    double total = 0;
    for (Expense expense : expenses) {
        PdfPCell c1 = new PdfPCell(new Phrase("" + ++i));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        table.addCell(dateFormat.format(new Date(expense.date * 1000)));
        table.addCell(expense.nature);
        table.addCell(expense.description);
        table.addCell("" + expense.account);
        c1 = new PdfPCell(new Phrase(DECIMAL_FORMAT.format(expense.amount) + " " + expense.currency));
        c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(c1);
        table.addCell(expense.voucher);
        total += expense.amount;
    }

    preface.add(table);

    preface.add(new Paragraph(" "));
    preface.add(new Paragraph("Total: " + DECIMAL_FORMAT.format(total), titleFont));

    document.add(preface);

    i = 0;
    for (Expense expense : expenses) {
        i++;
        if (expense.receipt == null)
            continue;

        document.newPage();
        Paragraph receipt = new Paragraph();
        receipt.add(new Paragraph("Attachment " + i, titleFont));
        document.add(receipt);
        Image image = Image.getInstance(new URL(expense.receipt));
        image.setRotationDegrees(-90);
        float scaler = (document.getPageSize().getWidth() / image.getWidth()) * 100;

        image.scalePercent(scaler);
        document.add(image);
    }

    document.close();
    stream.close();

    return stream.getSize();

}

From source file:com.mstoyanov.music_lessons.pdf.CreatePDF.java

License:Open Source License

private static PdfPTable createTable() throws DocumentException {
    PdfPTable table = new PdfPTable(6);
    table.setTotalWidth(new float[] { 114, 114, 114, 114, 114, 114 });
    table.setLockedWidth(true);//from  w  ww .j  a  va  2  s.  c om
    PdfPCell cell;

    cell = new PdfPCell(new Phrase("Monday", smallBold));
    // cell.setVerticalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Tuesday", smallBold));
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Wednesday", smallBold));
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Thursday", smallBold));
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Friday", smallBold));
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("Saturday", smallBold));
    table.addCell(cell);

    table.setHeaderRows(1);

    while (cells.size() > 0) { // rows
        for (int i = 0; i < weekdays_array.length; i++) { // columns
            boolean cell_empty = true;
            // scan all cell objects:
            for (int j = 0; j < cells.size(); j++) {
                // if there is a cell on this day:
                if (cells.get(j).getWeekDay().equalsIgnoreCase(weekdays_array[i])) {
                    Phrase phrase = new Phrase(
                            cells.get(j).getTimeFrom() + " - " + cells.get(j).getTimeTo() + "\n"
                                    + cells.get(j).getStudentName() + "\n" + cells.get(j).getPhoneNumber(),
                            smallFont);
                    // add it to the table:
                    table.addCell(phrase);
                    cell_empty = false;
                    cells.remove(j);
                    break;
                }
            }
            if (cell_empty) {
                // otherwise add an empty cell:
                table.addCell(new Phrase("\n" + "\n" + "\n", smallFont));
            }
        }
    }

    return table;
}

From source file:com.mx.ipn.clases.PDF.java

public PdfPTable Tabla_Simple() throws BadElementException, IOException {
    Paragraph paragraph1 = new Paragraph();
    Font nomb = FontFactory.getFont(FontFactory.TIMES_BOLD, 9, Font.NORMAL, BaseColor.DARK_GRAY);
    Image image;//from  www.  java 2 s  .  c  o  m

    // Obtenemos el logo de datojava
    image = Image.getInstance(getClass().getResource("/com/ipn/mx/imagenes/logo.png"));
    image.scaleAbsolute(70f, 60f);

    //creamos la tabla con 3 columnas
    PdfPTable mitablasimple = new PdfPTable(2);
    PdfPCell cellimage = new PdfPCell(image);

    // Propiedades de la celda

    cellimage.setBorderColor(BaseColor.WHITE);
    cellimage.setHorizontalAlignment(Element.ALIGN_CENTER);

    paragraph1.add(new Phrase("1. Nombre completo Y/O Razn Social.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("2. Direccin.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("3. Registro Federal de Contribuyentes Y/O CURP.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("4. Telfonos de Oficina y mviles.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("5. Actividad econmica e ingreso promedio.", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    paragraph1.add(new Phrase("6. Correo Electrnico. ", nomb));
    paragraph1.add(new Phrase(Chunk.NEWLINE));
    PdfPCell cell = new PdfPCell(paragraph1);

    // Propiedades de la celda

    cell.setBorderColor(BaseColor.WHITE);
    cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    mitablasimple.addCell(cell);
    mitablasimple.addCell(cellimage);
    //retornamos la tabla

    return mitablasimple;
}