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

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

Introduction

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

Prototype

public void addCell(final Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

From source file:beans.ManagedBeanReportes.java

public PdfPTable traerSubtabla(Tienda t) throws DocumentException {
    PdfPTable tabla_PesajeDetalle = new PdfPTable(4);
    tabla_PesajeDetalle.setWidthPercentage(100);
    tabla_PesajeDetalle.setTotalWidth(450f);
    tabla_PesajeDetalle.setLockedWidth(true);

    tabla_PesajeDetalle.setWidths(anchocol03);
    tabla_PesajeDetalle.getDefaultCell();

    PdfPCell Cell_Headers = new PdfPCell(new Paragraph("PRODUCTO", titulopequeFont));
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);

    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("UBICACIONES", titulopequeFont));
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("MINIMO", titulopequeFont));
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("STOCK TOTAL", titulopequeFont));
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    for (StockProductoTiendaOrigen det : stockProductoTiendaOrigenFacade.lista_stock_tienda(t)) {
        tabla_PesajeDetalle.addCell(traerCelda(det.getProducto().getNombreProducto()));
        String ubicaciones_ = "";
        for (DetalleAlmacenProductos p : detalleAlmacenProductosFacade.lista_para_stock_tienda(t,
                det.getProducto())) {//w w  w .j a v a2  s . c om
            if (p.getUbicacionFisica().getIdUbicacionFisica() > 1) {
                ubicaciones_ = p.getUbicacionFisica().getNombreUbicacionFisica() + ";" + ubicaciones_;
            }
        }
        tabla_PesajeDetalle.addCell(traerCelda(ubicaciones_));
        tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidadMinimaStock())));
        tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidad())));
    }
    return tabla_PesajeDetalle;
}

From source file:beans.OrdenDeTrabajoPDF.java

private void createPdf(String dest) throws IOException, DocumentException {
    Parametrizacion p = new Parametrizacion();
    this.listaPartes = new JsonParser().parse(ot.getPartes()).getAsJsonArray();
    this.listaDescripcionesTrabajos = new JsonParser().parse(ot.getDescripcionesTrabajos()).getAsJsonArray();
    this.listaMateriales = new JsonParser().parse(ot.getMateriales()).getAsJsonArray();

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/* ww w.  jav a2  s .co  m*/
    PdfPTable table = new PdfPTable(12);
    BaseColor color = new BaseColor(142, 170, 219);
    PdfPCell celda;
    Phrase texto;
    Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10);
    table.setWidthPercentage(100);

    Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png");
    celda = new PdfPCell(img, true);
    celda.setPadding(5);
    celda.setColspan(4);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("ORDEN DE TRABAJO N:" + this.ot.getNumeroOrdenDeTrabajo()
            + "\nFECHA INICIO:" + this.ot.getFechaInicio() + "\nFECHA FIN:" + this.ot.getFechaFin()
            + "\nSOLICITUD N:" + this.ot.getSolicitudDeMantenimiento().getCodigo() + "", font));
    celda.setColspan(8);
    // head.setBackgroundColor(BaseColor.CYAN);
    table.addCell(celda);
    String tipoSolicitud = ot.getTipoSolicitud();
    if (tipoSolicitud.equals("Urgente")) {
        celda = new PdfPCell(new Phrase("TIPO DE SOLICITUD    NORMAL:      URGENTE: X", font));
        celda.setColspan(12);
        table.addCell(celda);
    } else {
        celda = new PdfPCell(new Phrase("TIPO DE SOLICITUD    NORMAL: X    URGENTE:", font));
        celda.setColspan(12);
        table.addCell(celda);
    }

    if (ot.isDptAdmyControl()) {
        celda = new PdfPCell(new Phrase(
                "DTO.ADMS. Y CONTROL DE LA PRODUCCION" + " GENERA ORDEN DE TRABAJO DE MTTO SI:X           NO:",
                font));
        celda.setColspan(12);
        table.addCell(celda);
    } else {
        celda = new PdfPCell(new Phrase(
                "DTO.ADMS. Y CONTROL DE LA PRODUCCION" + " GENERA ORDEN DE TRABAJO DE MTTO SI:            NO:X",
                font));
        celda.setColspan(12);
        table.addCell(celda);
    }

    celda = new PdfPCell(
            new Phrase("CODIGO EQUIPO: " + ot.getSolicitudDeMantenimiento().getEquipo().getCodigo(), font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(
            new Phrase("NOMBRE EQUIPO: " + ot.getSolicitudDeMantenimiento().getEquipo().getNombre(), font));
    celda.setColspan(9);
    table.addCell(celda);
    String tipoMantenimiento = "";
    for (String element : ot.getTiposDeMantenimiento()) {
        tipoMantenimiento += element + "\n";
    }

    celda = new PdfPCell(new Phrase("TIPO DE MANTENIMIENTO\n", font));
    celda.setColspan(12);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(tipoMantenimiento, font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("PARTE", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("ANOMALIA", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("CAUSA", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("POSIBLE SOLUCION", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    for (int i = 0; i < listaPartes.size(); i++) {

        celda = new PdfPCell(new Phrase(
                listaPartes.get(i).getAsJsonObject().get("parte").toString().replace("\"", ""), font));
        celda.setColspan(3);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaPartes.get(i).getAsJsonObject().get("anomalia").toString().replace("\"", ""), font));
        celda.setColspan(3);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaPartes.get(i).getAsJsonObject().get("causa").toString().replace("\"", ""), font));
        celda.setColspan(3);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaPartes.get(i).getAsJsonObject().get("solucion").toString().replace("\"", ""), font));
        celda.setColspan(3);
        table.addCell(celda);

    }

    celda = new PdfPCell(new Phrase("SOLICTADA POR: " + ot.getSolicitadaPor() + "\n\nFIRMA", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("REVISADA POR: " + ot.getRevisadaPor() + "\n\nFIRMA", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("AUTORIZADA POR: " + ot.getAutorizadaPor() + "\n\nFIRMA", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("N", font));
    celda.setColspan(1);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS TRABAJOS A REALIZAR", font));
    celda.setColspan(11);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    for (int i = 0; i < listaDescripcionesTrabajos.size(); i++) {

        celda = new PdfPCell(new Phrase((i + 1) + "", font));
        celda.setColspan(1);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaDescripcionesTrabajos.get(i).getAsJsonObject().get("trabajo").toString().replace("\"", ""),
                font));
        celda.setColspan(11);
        table.addCell(celda);

    }

    celda = new PdfPCell(new Phrase("MATERIALES", font));
    celda.setColspan(12);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("N", font));
    celda.setColspan(1);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("CANTIDAD", font));
    celda.setColspan(2);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("REFERENCIA", font));
    celda.setColspan(2);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("VALOR UNI", font));
    celda.setColspan(2);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("VALOR TOTAL", font));
    celda.setColspan(2);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    for (int i = 0; i < listaMateriales.size(); i++) {
        celda = new PdfPCell(new Phrase("" + (1 + i), font));
        celda.setColspan(1);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("cantidad").toString().replace("\"", ""), font));
        celda.setColspan(2);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("descripcion").toString().replace("\"", ""),
                font));
        celda.setColspan(3);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("referencia").toString().replace("\"", ""), font));
        celda.setColspan(2);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("unitario").toString().replace("\"", ""), font));
        celda.setColspan(2);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("total").toString().replace("\"", ""), font));
        celda.setColspan(2);
        table.addCell(celda);
    }
    celda = new PdfPCell(new Phrase("COSTOS", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MANO DE OBRA: $" + ot.getCostoManoDeObra() + "", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("MATERIALES: $" + ot.getCostoMateriales() + "", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL: $" + ot.getCostoTotal() + "", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TIEMPO EMPLEADO", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS MTO: " + ot.getTotalHorasMto() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS PARADA: " + ot.getTotalHorasParada() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS DAOS ENCONTRADOS", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + ot.getDescripcionDanos(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS TRABAJOS REALIZADOS", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + ot.getDescripcionTrabajosRealizados(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("OBSERVACIONES Y RECOMENDACIONES", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + ot.getObservaciones(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("EJECUTO: " + ot.getEjecutadoPor() + "\n\nFIRMA", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("RECIBI Y APROB: " + ot.getRecibidoAprobadoPor() + "\n\nFIRMA", font));
    celda.setColspan(6);
    table.addCell(celda);

    document.add(table);
    document.close();
}

From source file:beans.SolicitudDeMantenimientoPDF.java

public void createPdf(String dest) throws IOException, DocumentException {
    Parametrizacion p = new Parametrizacion();
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();// www .  jav a 2s. co m
    PdfPTable table = new PdfPTable(12);
    Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10);
    PdfPCell celda;
    table.setWidthPercentage(100);

    Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png");
    celda = new PdfPCell(img, true);
    celda.setPadding(5);
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("CODIGO: " + sm.getCodigo() + "\nREVISION: " + sm.getRevision()
            + "\nSOLICITUD DE SERVICIO: " + sm.getSolicitudDeServicio() + "\nFECHA: " + sm.getFecha() + "",
            font));
    celda.setColspan(8);
    // head.setBackgroundColor(BaseColor.CYAN);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SECCION", font));
    celda.setColspan(4);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MAQUINA", font));
    celda.setColspan(4);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("NOMBRE DEL OPERARIO", font));
    celda.setColspan(4);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getEquipo().getUbicacion(), font));
    celda.setColspan(4);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("" + sm.getEquipo().getNombre(), font));
    celda.setColspan(4);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("" + sm.getEquipo().getOperario(), font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    String reparacion = " ";
    String mtoMecanico = " ";
    String mtoPreventivo = " ";
    String mtoElectrico = " ";
    String mtoCorrectivo = " ";
    String otros = " ";
    if (sm.isReparacion()) {
        reparacion += " X";
    }
    if (sm.isMtoMecanico()) {
        mtoMecanico += " X";
    }
    if (sm.isMtoPreventivo()) {
        mtoPreventivo += " X";
    }
    if (sm.isMtoElectrico()) {
        mtoElectrico += " X";
    }
    if (sm.isMtoCorrectivo()) {
        mtoCorrectivo += " X";
    }
    if (sm.isOtros()) {
        otros += " X";
    }

    celda = new PdfPCell(new Phrase("REPARACION", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(reparacion, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. MECANICO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoMecanico, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. PREVENTIVO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoPreventivo, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. ELECTRICO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoElectrico, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. CORRECTIVO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoCorrectivo, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("OTROS", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(otros, font));
    celda.setColspan(1);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DEL SERVICIO SOLICITADO", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getDescripcionServicio(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DE ACCIONES A REALIZAR", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getDescripcionAcciones(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("MATERIAL A EMPLEAR", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getMaterial(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("GENERALIDADES", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS PARADA: " + sm.getHorasParada() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("HORA SOLICITUD: " + sm.getHoraSolicitud() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS MTO: " + sm.getHorasMTO() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("HORA ENTREGA: " + sm.getHoraEntrega() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO POR: " + sm.getSolicitadoPor() + "\n"
            + "SERVICIO REALIZADO POR: " + sm.getRealizadoPor() + "\n" + "RECIBO A CONFORMIDAD: "
            + sm.getRecibidoPor() + "\n\n\n FIRMA", font));
    celda.setColspan(12);
    table.addCell(celda);
    document.add(table);
    document.close();
}

From source file:bemyguest.controller.ValidationResevation.java

@FXML
private void handleButtonValiderAction(ActionEvent event) throws FileNotFoundException, DocumentException {
    Resrevation e = tab_reservation.getSelectionModel().getSelectedItem();
    if (e == null) {

        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setTitle("Warning Dialog");
        alert.setHeaderText(null);/* ww  w.  j  a v a 2s . c  o  m*/
        alert.setContentText("selectionner un demande de  reservation a traiter svp!");

        alert.showAndWait();
        LoadData();
        setCellTable();
    }

    else {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle("Confiramtion");
        alert.setHeaderText(null);
        alert.setContentText("vous etes sur d'accepter cette demande de reservation");
        Optional<ButtonType> answer = alert.showAndWait();

        if (answer.get() == ButtonType.OK) {
            ResevationDAO dao = new ResevationDAO();
            if (dao.ajouter_Reservation(e)) {

                LoadData();
                setCellTable();

                alert.setTitle("Success Dialog");
                alert.setHeaderText(null);
                alert.setContentText("Demandes accepter avec success");

                alert.showAndWait();

                try {

                    Document d = new Document(PageSize.A4.rotate());
                    PdfWriter.getInstance(d, new FileOutputStream(e.getUser().getNom() + "Facture.pdf"));
                    d.open();

                    d.add(new Paragraph("BeMyGuest Facture :",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
                    d.add(new Paragraph(new Date().toString()));
                    d.add(new Paragraph(
                            "-------------------------------------------------------------------------------------------------------------"));
                    d.add(new Paragraph("             "));
                    d.add(new Paragraph("             "));
                    PdfPTable pdt = new PdfPTable(7);
                    PdfPCell cell = new PdfPCell(new Paragraph("Composant de facture"));
                    cell.setColspan(7);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell.setBackgroundColor(BaseColor.RED);
                    pdt.addCell(cell);

                    pdt.addCell(new Paragraph("Nom:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Prenom:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Date Debut:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Date Fin:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("nbre chambre:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("nbre personne:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Prix:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getUserDemandant().getNom(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getUserDemandant().getPrenom(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getDateDebut().toString(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getDateFin().toString(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(e.getDateDebut().toString());

                    int nb = e.getPropriete().getNbrChambre();

                    float pr = e.getPropriete().getPrix();
                    int nbp = e.getPropriete().getNbrVoyageur();
                    pdt.addCell(new Paragraph(Integer.toString(nb),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(Integer.toString(nbp),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(Float.toString(pr),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));

                    pdt.addCell(Float.toString(pr));

                    d.add(pdt);
                    d.close();
                } catch (Exception b) {

                    JOptionPane.showMessageDialog(null, b);
                }
            } else {
                alert.setTitle("Error Dialog");
                alert.setHeaderText(null);
                alert.setContentText("Cette Propriete Reserver pendant cette date ");

                alert.showAndWait();

                LoadData();
                setCellTable();
            }
        }

        else {
            LoadData();
            setCellTable();
        }
    }

}

From source file:bestdeal.util.genererPdf.java

public static void main(String[] args) {
    // - Paramtres de connexion  la base de donnes
    Connection connection;//from   w ww .  j a  va  2 s .c  om
    String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " },
            { " ", " ", " ", " ", " " }, };

    try {
        String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur";
        connection = MyConnection.getInstance();
        mypdf = new Document(PageSize.A4, 50, 50, 50, 50);
        File di = new File("C:/Voucher");
        File fl[] = di.listFiles();
        try {
            OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf"));
            PdfWriter.getInstance(mypdf, file);

            mypdf.open();
            Statement stm;

            mypdf.addAuthor("Best Deal");
            mypdf.addSubject("Voucher ");
            mypdf.add(new Paragraph("Socite BestDeal"));
            mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT "));
            mypdf.add(new Paragraph("TEL : xx xxx xxx"));
            mypdf.add(new Paragraph("FAX : xx xxx xxx"));
            mypdf.add(new Paragraph(
                    "                                                                                                       "
                            + new Date().toString()));
            mypdf.add(new Paragraph("  "));
            mypdf.add(new Paragraph("                                   " + "Voucher N'01",
                    FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC)));
            mypdf.add(new Paragraph("  "));

            mypdf.add(new Paragraph("CLIENT :",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));
            try {
                stm = connection.createStatement();
                ResultSet rs = stm.executeQuery(requete);

                while (rs.next()) {
                    // add a country to the document as a Chunk
                    //mypdf.add(new Chunk(rs.getString("quantite")));
                    Phrase p = new Phrase("Nom:   ");
                    Phrase p2 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa = new Paragraph();
                    pa.add(p);
                    pa.add(p2);
                    mypdf.add(pa);

                    Phrase p3 = new Phrase("Prenom:  ");
                    Phrase p4 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa1 = new Paragraph();
                    pa1.add(p3);
                    pa1.add(p4);
                    mypdf.add(pa1);

                    Phrase p5 = new Phrase("Adresse:  ");
                    Phrase p6 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa2 = new Paragraph();
                    pa2.add(p5);
                    pa2.add(p6);
                    mypdf.add(pa2);

                    Phrase p7 = new Phrase("Tlphone:  ");
                    Phrase p8 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa3 = new Paragraph();
                    pa3.add(p7);
                    pa3.add(p8);
                    mypdf.add(pa3);

                    mypdf.add(new Paragraph("  "));

                    mypdf.add(new Paragraph("Vendeur :",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));

                    Phrase p9 = new Phrase("Nom:  ");
                    Phrase p10 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa4 = new Paragraph();
                    pa4.add(p9);
                    pa4.add(p10);
                    mypdf.add(pa4);

                    Phrase p11 = new Phrase("Prnom:  ");
                    Phrase p12 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa5 = new Paragraph();
                    pa5.add(p11);
                    pa5.add(p12);
                    mypdf.add(pa5);

                    Phrase p13 = new Phrase("Tlphone:  ");
                    Phrase p14 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa6 = new Paragraph();
                    pa6.add(p13);
                    pa6.add(p14);
                    mypdf.add(pa6);

                    Phrase p15 = new Phrase("Adresse:  ");
                    Phrase p16 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa7 = new Paragraph();
                    pa7.add(p15);
                    pa7.add(p16);
                    mypdf.add(pa7);

                    Phrase p17 = new Phrase("Email:  ");
                    Phrase p18 = new Phrase(new Chunk(rs.getString("email")));
                    Paragraph pa8 = new Paragraph();
                    pa8.add(p17);
                    pa8.add(p18);
                    mypdf.add(pa8);

                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));

                    for (int i = 0; i < rs.getRow(); i++) {
                        for (int j = 0; j < data[i].length - 1; j++) {
                            data[i][j] = rs.getString(j + 9);
                            // if (j==3)
                            //     data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+"";
                        }
                    }

                    for (int i = 0; i < rs.getRow(); i++) {
                        float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim());
                        data[i][4] = s + "";
                    }

                    //mypdf.add(new Phrase("nom"));
                    //mypdf.add(new  Chunk(rs.getString("nom")));
                    //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom"))));
                    //mypdf.add(new Chunk(" "));
                    //Chunk id = new Chunk(rs.getString("id"));
                    // with a background color
                    //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
                    // and a text rise
                    //id.setTextRise(6);
                    //  mypdf.add(id);
                    mypdf.add(Chunk.NEWLINE);
                }

            } catch (SQLException ex) {
                Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
            // mypdf.add(new Paragraph("Nom "));
            //  mypdf.add(new Paragraph("Prenom "));
            // mypdf.add(new Paragraph("Adresse "));
            //mypdf.add(new Paragraph("Tlphone "));

            // mypdf.add(new Paragraph("Nom "));
            // mypdf.add(new Paragraph("Nom de la socit "));
            //  mypdf.add(new Paragraph("Adresse "));
            // mypdf.add(new Paragraph("Tlphone "));
            // mypdf.add(new Paragraph("  "));

            String[] headers = new String[] { "  Id_deal", "   Nom Deal", "   Quantit", "    Prix unitaire",
                    "   Prix total" };
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase()));
                table.addCell(cell);
            }
            table.completeRow();
            for (int i = 0; i < data.length; i++) {
                for (int j = 0; j < data[i].length; j++) {
                    String datum = data[i][j];
                    PdfPCell cell = new PdfPCell();
                    cell.setPhrase(new Phrase(datum.toUpperCase()));
                    table.addCell(cell);
                }
                table.completeRow();
            }

            mypdf.add(table);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
        }

        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(
                "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ",
                FontFactory.getFont(null, 9, Font.NORMAL)));
        mypdf.add(new Paragraph(
                "                                                      Merci pour votre confiance",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC)));
        mypdf.add(new Paragraph("      "));
        mypdf.add(new Paragraph("  "));
        mypdf.add(new Paragraph("  "));

        mypdf.close();

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

From source file:biblioteca.BibliotecaFXMLController.java

@FXML /// Arquivo - PDF - Tabela Alunos
public void pdf() throws FileNotFoundException, DocumentException, IOException, SQLException {
    Document doc = null;/*ww w .ja  va2s  .c  om*/
    OutputStream os = null;
    try {
        contest conn = new contest();
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4);
        //cria a stream de sada
        os = new FileOutputStream("TabelaA.pdf");
        //associa a stream de sada ao
        PdfWriter.getInstance(doc, os);
        //abre o documento
        doc.open();
        //adiciona o texto ao PDF 
        PdfPTable tabelaA = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.9f, 0.7f });
        PdfPCell header = new PdfPCell(new Paragraph("Tabela de Alunos"));
        header.setColspan(5);
        tabelaA.addCell(header);
        tabelaA.addCell("ID");
        tabelaA.addCell("Matrcula");
        tabelaA.addCell("Nome");
        tabelaA.addCell("C.P.F");
        tabelaA.addCell("Telefone");
        Statement stA = conn.conectar1().createStatement();
        ResultSet rsa = stA.executeQuery("SELECT idAluno,matriculaAluno,nomeAluno,nCPF,Telefone FROM `Aluno`;");
        while (rsa.next()) {
            Aluno a = new Aluno(0, 0, "", "", "");
            a.setIdaluno(rsa.getInt("idAluno"));
            a.setMatricula(rsa.getInt("matriculaAluno"));
            a.setNoAluno(rsa.getString("nomeAluno"));
            a.setCpf(rsa.getString("nCPF"));
            a.setTelefone(rsa.getString("Telefone"));

            tabelaA.addCell(String.valueOf(a.getIdaluno()));
            tabelaA.addCell(String.valueOf(a.getMatricula()));
            tabelaA.addCell(a.getNoAluno());
            tabelaA.addCell(a.getCpf());
            tabelaA.addCell(a.getTelefone());

        }
        doc.add(tabelaA);
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}

From source file:biblioteca.BibliotecaFXMLController.java

@FXML /// Arquivo - PDF - Tabela Livros
public void pdfL() throws FileNotFoundException, DocumentException, IOException, SQLException {
    Document doc = null;/*w w  w.  ja  v a 2 s  .  co m*/
    OutputStream os = null;
    try {
        contest conn = new contest();
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4);
        //cria a stream de sada
        os = new FileOutputStream("TabelaL.pdf");
        //associa a stream de sada ao
        PdfWriter.getInstance(doc, os);
        //abre o documento
        doc.open();
        //adiciona o texto ao PDF
        PdfPTable tabelaL = new PdfPTable(new float[] { 0.1f, 0.7f, 0.7f, 0.1f });
        PdfPCell header = new PdfPCell(new Paragraph("Tabela de Livros"));
        header.setColspan(4);
        tabelaL.addCell(header);
        tabelaL.addCell("ID");
        tabelaL.addCell("Ttulo");
        tabelaL.addCell("Autor");
        tabelaL.addCell("Qtde.");

        Statement st = conn.conectar1().createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM `Livro`;");
        while (rs.next()) {
            Livro l = new Livro(0, "", "", 0, 0);
            l.setIdlivro(rs.getInt("idlivro"));
            l.setTiLivro(rs.getString("nomeLivro"));
            l.setNoAutor(rs.getString("nomeAutor"));
            l.setQtdeLivro(rs.getInt("qtdelivro"));

            tabelaL.addCell(String.valueOf(l.getIdlivro()));
            tabelaL.addCell(l.getTiLivro());
            tabelaL.addCell(l.getNoAutor());
            tabelaL.addCell(String.valueOf(l.getQtdeLivro()));
        }
        doc.add(tabelaL);
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}

From source file:biblioteca.BibliotecaFXMLController.java

@FXML /// Arquivo - PDF - Tabela Reservas
public void pdfR() throws FileNotFoundException, DocumentException, IOException, SQLException {
    Document doc = null;/* w  w  w  . j a v  a 2 s .  co m*/
    OutputStream os = null;
    try {
        contest conn = new contest();
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4);
        //cria a stream de sada
        os = new FileOutputStream("Tabela de Reservas.pdf");
        //associa a stream de sada ao
        PdfWriter.getInstance(doc, os);
        //abre o documento
        doc.open();
        //adiciona o texto ao PDF
        PdfPTable tabelaR = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.7f, 0.7f });
        PdfPCell header = new PdfPCell(new Paragraph("Tabela de Reservas"));
        header.setColspan(5);
        tabelaR.addCell(header);
        tabelaR.addCell("ID");
        tabelaR.addCell("Ttulo do Livro");
        tabelaR.addCell("Aluno");
        tabelaR.addCell("Data de Saida");
        tabelaR.addCell("Data de Entrega");

        Statement stR = conn.conectar1().createStatement();
        ResultSet rsr = stR.executeQuery(
                "SELECT Itens.id_Itens as \"Item\", Itens.id_reserva AS \"Reserva\", Aluno.nomeAluno "
                        + "as \"Aluno\", Itens.id_Livro as \"idLivro\", Livro.nomeLivro AS \"NomeLivro\", Reserva.dataRetirada AS \"DataSaida\", Reserva.dataEntrega as \"DataEntrega\""
                        + "FROM Itens JOIN Reserva ON id_reserva = Reserva.idReserva\n"
                        + "JOIN Aluno ON Reserva.idAluno = Aluno.idAluno\n"
                        + "JOIN Livro ON Livro.idLivro = Itens.id_Livro;");
        while (rsr.next()) {
            Reserva r = new Reserva(0, 0, "", 0, "", "", "");

            r.setIdItem(rsr.getInt("Item"));
            r.setIdReserva(rsr.getInt("Reserva"));
            r.setNoAluno(rsr.getString("Aluno"));
            r.setIdLivro(rsr.getInt("idLivro"));
            r.setNoLivro(rsr.getString("NomeLivro"));
            r.setDaSaida(rsr.getString("DataSaida"));
            r.setDaEntrada(rsr.getString("DataEntrega"));

            tabelaR.addCell(String.valueOf(r.getIdReserva()));
            tabelaR.addCell(r.getNoLivro());
            tabelaR.addCell(r.getNoAluno());
            tabelaR.addCell(r.getDaSaida());
            tabelaR.addCell(r.getDaEntrada());

        }
        doc.add(tabelaR);
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}

From source file:biblioteca.reportes.PdfCreator.java

License:Open Source License

/**
 * Dado un resultSet obtenido de una consulta, esta funcin convierte los datos
 * internos de este en una tabla que puede ser insertada en un Document de iText
 * esta PdfPTable tiene en su primera linea los nombres de las columnas del ResultSet
 * @param entrada ResultSet El resultado de una consulta a la base de datos
 * @return una PdfPTable para insertar en un documento de iText
 * @see com.itextpdf.text.pdf.PdfPTable;
 * @see java.sql.ResultSet;//from w ww  .  ja  v a  2 s .  c o m
 */
static public PdfPTable resultSetToTable(ResultSet entrada) {
    PdfPTable salida = null;
    try {
        ResultSetMetaData rsmd = entrada.getMetaData();

        salida = new PdfPTable(rsmd.getColumnCount());
        for (int i = 1; i <= rsmd.getColumnCount(); i++) {
            salida.addCell(rsmd.getColumnName(i));
        }
        salida.setHeaderRows(1);
        while (entrada.next()) {
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                salida.addCell(entrada.getString(i));
            }
        }
    } catch (java.sql.SQLException sqlex) {
        System.err.println(sqlex);
    }
    return salida;
}

From source file:biblioteca.reportes.PdfCreator.java

License:Open Source License

static public PdfPTable plainArrayListToPdfPTable(ArrayList<String> entrada, int columns) {
    PdfPTable salida = new PdfPTable(columns);
    for (int i = 0; i < columns; i++) {
        salida.addCell(entrada.get(i));
    }/*from   w  ww  . j a  va 2  s .co m*/
    salida.setHeaderRows(1);
    for (int i = columns; i < entrada.size(); i++) {
        salida.addCell(entrada.get(i));
    }
    return salida;
}