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:alessandrafx.MarcoVentanaController.java

@FXML
private void generarReporteMenusal(MouseEvent event) {

    try {//from  w  w w.  j a va 2 s .c o  m
        FileChooser fileChooser = new FileChooser();
        fileChooser.setInitialFileName("Reporte.pdf");
        File file = fileChooser.showSaveDialog(null);
        file.getParentFile().mkdir();

        Document document = new Document();
        try {
            try {
                PdfWriter.getInstance(document, new FileOutputStream(file));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }

        document.open();
        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date()));
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        SistemaAleMC sistema = new SistemaAleMC();
        Double balanceMonetario = 0.0;

        //Para salidas de dinero
        ArrayList<Capital> capitales = sistema.getRegistrosCapitalTipo('S');
        cell = new PdfPCell(new Phrase("Gastos y pagos realizados"));
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        //Agrega los registros de salidas de dinero
        Double totalEgreso = 0.0;
        if (capitales.isEmpty()) {
            cell = new PdfPCell(new Phrase(" --- "));
            cell.setColspan(2);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(" --- "));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
        }
        for (Capital capital : capitales) {
            cell = new PdfPCell(new Phrase(capital.getMotivo().toString()));
            cell.setColspan(2);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(capital.getMonto().toString()));
            balanceMonetario -= Double.valueOf(capital.getMonto());
            totalEgreso -= Double.valueOf(capital.getMonto());
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
        }
        cell = new PdfPCell(new Phrase("TOTAL DE EGRESOS"));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(totalEgreso.toString()));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);

        //Para Pago de mensualidades
        capitales = sistema.getRegistrosCapitalTipo('M');
        cell = new PdfPCell(new Phrase("Pagos de mensualidad recibidos"));
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        //Agrega los registros de pago de mensualidades de los alumnos
        Double totalIngresoMen = 0.0;
        if (capitales.isEmpty()) {
            cell = new PdfPCell(new Phrase(" --- "));
            cell.setColspan(2);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(" --- "));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
        }
        for (Capital capital : capitales) {
            cell = new PdfPCell(new Phrase(capital.getMotivo().toString()));
            cell.setColspan(2);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(capital.getMonto().toString()));
            balanceMonetario += Double.valueOf(capital.getMonto());
            totalIngresoMen += Double.valueOf(capital.getMonto());
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
        }
        cell = new PdfPCell(new Phrase("TOTAL DE MENSUALIDADES"));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(totalIngresoMen.toString()));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);

        //Para Pago de anualidades
        capitales = sistema.getRegistrosCapitalTipo('A');
        cell = new PdfPCell(new Phrase("Pagos de anualidades recibidos"));
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        //Agrega los registros de pago de anualidades de los alumnos
        Double totalIngresoAnu = 0.0;
        if (capitales.isEmpty()) {
            cell = new PdfPCell(new Phrase(" --- "));
            cell.setColspan(2);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(" --- "));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
        }
        for (Capital capital : capitales) {
            cell = new PdfPCell(new Phrase(capital.getMotivo().toString()));
            cell.setColspan(2);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(capital.getMonto().toString()));
            balanceMonetario += Double.valueOf(capital.getMonto());
            totalIngresoAnu += Double.valueOf(capital.getMonto());
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
        }
        cell = new PdfPCell(new Phrase("TOTAL DE ANUALIDADES"));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(totalIngresoAnu.toString()));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);

        //PARA EL BALANCE MONETARIO
        capitales = sistema.getRegistrosCapitalTipo('A');
        cell = new PdfPCell(new Phrase("Total"));
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        //Agrega la celda del total monetario
        if (balanceMonetario == (Double) 0.0) {
            cell = new PdfPCell(new Phrase("No hubieron movimientos este mes"));
        } else {
            cell = new PdfPCell(new Phrase(balanceMonetario.toString()));
        }
        cell.setColspan(3);
        cell.setBackgroundColor(BaseColor.WHITE);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);

        try {
            document.add(table);
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.close();
        Alert alerta = new Alert(Alert.AlertType.INFORMATION);
        alerta.setTitle("Corre a ver tu PDF!");
        alerta.setHeaderText(null);
        alerta.setContentText("El PDF ha sido generado, puedes revisarlo");
        alerta.showAndWait();

    } catch (Exception e) {
        Alert alerta = new Alert(Alert.AlertType.INFORMATION);
        alerta.setTitle("Lo sentimos");
        alerta.setHeaderText(null);
        alerta.setContentText("La ubicacin seleccionada no es vlida y por tanto, no se generar el PDF");
        alerta.showAndWait();
    }
}

From source file:alessandrafx.VentanaEgresoController.java

private void generarReportePagoColaborador(int pagoColaborador, int pagoSugerido) throws DatoFaltante {
    try {//from   w ww. j a  v a  2  s . c  o m
        FileChooser fileChooser = new FileChooser();
        fileChooser.setInitialFileName("facturaNueva.pdf");
        File file = fileChooser.showSaveDialog(null);
        file.getParentFile().mkdir();

        Document document = new Document();
        try {
            try {
                PdfWriter.getInstance(document, new FileOutputStream(file));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }

        document.open();
        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date()));
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        //Agrega el pago IDEAL
        cell = new PdfPCell(new Phrase("Pago sugerido recibido"));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Pago sugerido"));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);

        //Agrega el pago realizado
        cell = new PdfPCell(new Phrase("Pago realizado"));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(String.valueOf(pagoColaborador)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);
        try {
            document.add(table);
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.close();

    } catch (Exception e) {
        throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida");
    }

}

From source file:alessandrafx.VentanaEgresoController.java

private void generarReporteOtroGasto(int cantidad, String motivo) throws DatoFaltante {
    try {/*from   w ww  .  j a  v a  2s  .  c  o m*/
        FileChooser fileChooser = new FileChooser();
        fileChooser.setInitialFileName("facturaHecha.pdf");
        File file = fileChooser.showSaveDialog(null);
        file.getParentFile().mkdir();

        Document document = new Document();
        try {
            try {
                PdfWriter.getInstance(document, new FileOutputStream(file));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }

        document.open();
        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date()));
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        //Agrega el monto pagado
        cell = new PdfPCell(new Phrase("Pago realizado"));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(String.valueOf(cantidad)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);

        //Agrega el motivo del pago
        cell = new PdfPCell(new Phrase("Motivo: \n" + motivo));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setColspan(3);
        table.addCell(cell);
        try {
            document.add(table);
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.close();

    } catch (Exception e) {
        throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida");
    }

}

From source file:alessandrafx.VentanaIngresoController.java

public void generarReportePago(String pagoSugerido, String pagoRealizado) throws DatoFaltante {

    try {/*from  w  w w .ja  v  a 2 s.c  om*/
        FileChooser fileChooser = new FileChooser();
        fileChooser.setInitialFileName("facturaNueva.pdf");
        File file = fileChooser.showSaveDialog(null);
        file.getParentFile().mkdir();

        Document document = new Document();
        try {
            try {
                PdfWriter.getInstance(document, new FileOutputStream(file));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }

        document.open();
        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Phrase("Factura emitida el " + new Date()));
        cell.setColspan(3);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        //Agrega el pago IDEAL
        cell = new PdfPCell(new Phrase("Pago sugerido recibido"));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(pagoSugerido));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);

        //Agrega el pago realizado
        cell = new PdfPCell(new Phrase("Pago realizado"));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(String.valueOf(pagoRealizado)));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);
        try {
            document.add(table);
        } catch (DocumentException ex) {
            Logger.getLogger(VentanaEgresoController.class.getName()).log(Level.SEVERE, null, ex);
        }
        document.close();

    } catch (Exception e) {
        throw new DatoFaltante("ubicacin no vlida", "La ubicacin que has escogido no es vlida");
    }
}

From source file:Almacen.Conciliacion.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
     // TODO add your handling code here:
     try {/*from  w w w .ja va2s .  c  om*/
         javax.swing.JFileChooser archivo = new javax.swing.JFileChooser();
         archivo.setFileFilter(new ExtensionFileFilter("pdf document (*.pdf)", new String[] { "PDF" }));
         String ruta = null;

         if (archivo.showSaveDialog(null) == archivo.APPROVE_OPTION) {
             ruta = archivo.getSelectedFile().getAbsolutePath();
             if (ruta != null) {
                 Session session = HibernateUtil.getSessionFactory().openSession();
                 ArrayList datos = new ArrayList();
                 Query query = session.createSQLQuery(
                         "select compania.nombre, orden.tipo_nombre, orden.modelo, orden.no_serie, clientes.nombre as nombres,orden.id_orden \n"
                                 + "from orden inner join compania on compania.id_compania=orden.id_compania inner join clientes on clientes.id_clientes=orden.id_cliente\n"
                                 + "where orden.id_orden=" + Integer.parseInt(orden) + "");
                 query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
                 datos = (ArrayList) query.list();

                 //
                 PDF reporte = new PDF();
                 reporte.Abrir2(PageSize.LEGAL.rotate(), "CONCILIACIN", ruta + ".pdf");
                 BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                 float[] nuevos = new float[] { 40, 40, 25, 40, 145, 20, 50, 50, 50, 50, 50, 50, 100, 50, 20 };
                 com.itextpdf.text.Font font = new com.itextpdf.text.Font(
                         com.itextpdf.text.Font.FontFamily.HELVETICA, 7, com.itextpdf.text.Font.NORMAL);
                 com.itextpdf.text.Font font1 = new com.itextpdf.text.Font(
                         com.itextpdf.text.Font.FontFamily.HELVETICA, 7, com.itextpdf.text.Font.NORMAL);
                 BaseColor contenido = BaseColor.WHITE;
                 BaseColor contenido1 = BaseColor.DARK_GRAY;
                 int centro = com.itextpdf.text.Element.ALIGN_CENTER;
                 int izquierda = com.itextpdf.text.Element.ALIGN_LEFT;
                 int derecha = com.itextpdf.text.Element.ALIGN_RIGHT;

                 reporte.inicioTexto();
                 reporte.agregaObjeto(reporte.crearImagen("imagenes/empresa300115.jpg", 730, -90, 45));
                 reporte.contenido.setFontAndSize(bf, 20);
                 reporte.contenido.setColorFill(BaseColor.BLACK);
                 reporte.contenido.showTextAligned(PdfContentByte.ALIGN_CENTER,
                         "CONCILIACIN PARA FACTURACIN", 395, 577, 0);

                 reporte.contenido.setFontAndSize(bf, 12);
                 reporte.contenido.setColorFill(BaseColor.BLACK);
                 reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "COMPAIA:", 38, 540, 0);
                 reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "TIPO DE UNIDAD:", 38, 520, 0);
                 reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "MODELO:", 38, 500, 0);
                 reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "SERIE VIN:", 38, 480, 0);
                 reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "CLIENTE:", 38, 460, 0);

                 reporte.contenido.roundRectangle(170, 540, 410, 0, 0);
                 reporte.contenido.roundRectangle(170, 520, 410, 0, 0);
                 reporte.contenido.roundRectangle(170, 500, 410, 0, 0);
                 reporte.contenido.roundRectangle(170, 480, 410, 0, 0);
                 reporte.contenido.roundRectangle(170, 460, 410, 0, 0);

                 reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ORDEN DE TRABAJO SET.", 605, 540,
                         0);
                 reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ORDEN DE SURTIDO", 620, 480, 0);

                 for (int i = 0; i < datos.size(); i++) {
                     java.util.HashMap map = (java.util.HashMap) datos.get(i);
                     reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("nombre").toString(),
                             171, 540, 0);
                     reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                             map.get("tipo_nombre").toString(), 171, 520, 0);
                     reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("modelo").toString(),
                             171, 500, 0);
                     reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("no_serie").toString(),
                             171, 480, 0);
                     reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("nombres").toString(),
                             171, 460, 0);
                     reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("id_orden").toString(),
                             657, 520, 0);
                 }
                 reporte.contenido.roundRectangle(640, 520, 80, 0, 0);
                 reporte.contenido.roundRectangle(640, 460, 80, 0, 0);

                 reporte.finTexto();

                 reporte.agregaObjeto(new Paragraph(" "));
                 reporte.agregaObjeto(new Paragraph(" "));
                 reporte.agregaObjeto(new Paragraph(" "));

                 reporte.agregaObjeto(new Paragraph(" "));
                 reporte.agregaObjeto(new Paragraph(" "));

                 reporte.agregaObjeto(new Paragraph(" "));
                 reporte.agregaObjeto(new Paragraph(" "));

                 PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_CENTER);
                 cabecera(reporte, bf, tabla, "", 2);
                 DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");

                 int num_r = t_datos.getRowCount();
                 for (int i = 0; i < num_r; i++) {
                     for (int j = 0; j < 4; j++) {
                         int renglon = 0;
                         switch (j) {
                         case 0:
                             renglon = 8;
                             break;
                         case 1:
                             renglon = 10;
                             break;
                         case 2:
                             renglon = 11;
                             break;
                         case 3:
                             renglon = 12;
                             break;
                         }
                         if ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0
                                 && t_datos.getValueAt(i, 9).toString().compareTo("N") == 0)
                                 || ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0
                                         && renglon >= 10))
                                 || (renglon == 8
                                         && Double.parseDouble(t_datos.getValueAt(i, 10).toString()) <= 0
                                         && Double.parseDouble(t_datos.getValueAt(i, 11).toString()) <= 0
                                         && Double.parseDouble(t_datos.getValueAt(i, 12).toString()) <= 0)) {
                             if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0)
                                 contenido = BaseColor.WHITE;
                             else
                                 contenido = BaseColor.LIGHT_GRAY;

                             if ((boolean) t_datos.getValueAt(i, 3) == true
                                     || (boolean) t_datos.getValueAt(i, 4) == true) {
                                 //columna0
                                 if (t_datos.getValueAt(i, 5) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 5).toString(), font,
                                             contenido, centro, 0, 1, Rectangle.RECTANGLE));
                                 }
                                 //columna1
                                 if (t_datos.getValueAt(i, 6) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 6).toString(), font,
                                             contenido, centro, 0, 1, Rectangle.RECTANGLE));
                                 }
                                 //columna2
                                 tabla.addCell(reporte.celda(t_datos.getValueAt(i, renglon).toString(), font,
                                         contenido, centro, 0, 1, Rectangle.RECTANGLE));

                                 //columna3
                                 if (t_datos.getValueAt(i, 14) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 14).toString(), font,
                                             contenido, centro, 0, 1, Rectangle.RECTANGLE));
                                 }
                                 //columna4
                                 tabla.addCell(reporte.celda(t_datos.getValueAt(i, 2).toString(), font,
                                         contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                                 //columna5
                                 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0)
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 else {
                                     switch (renglon) {
                                     case 8:
                                         tabla.addCell(reporte.celda("N", font, contenido, centro, 0, 1,
                                                 Rectangle.RECTANGLE));
                                         break;
                                     case 10:
                                         tabla.addCell(reporte.celda("D", font, contenido, centro, 0, 1,
                                                 Rectangle.RECTANGLE));
                                         break;
                                     case 11:
                                         tabla.addCell(reporte.celda("R", font, contenido, centro, 0, 1,
                                                 Rectangle.RECTANGLE));
                                         break;
                                     case 12:
                                         tabla.addCell(reporte.celda("M", font, contenido, centro, 0, 1,
                                                 Rectangle.RECTANGLE));
                                         break;
                                     }
                                 }
                                 //columna6
                                 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 15)),
                                         font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                 //columna7 $tot aut.
                                 double n;
                                 n = BigDecimal
                                         .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString())
                                                 * Double.parseDouble(t_datos.getValueAt(i, 15).toString()))
                                         .setScale(2, RoundingMode.UP).doubleValue();
                                 tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido,
                                         derecha, 0, 1, Rectangle.RECTANGLE));
                                 //columna8
                                 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 16)),
                                         font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                                 //columna9 $tot com
                                 n = BigDecimal
                                         .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString())
                                                 * Double.parseDouble(t_datos.getValueAt(i, 16).toString()))
                                         .setScale(2, RoundingMode.UP).doubleValue();
                                 tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido,
                                         derecha, 0, 1, Rectangle.RECTANGLE));

                                 //columna10 11
                                 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     switch (renglon) {
                                     case 8:
                                         n = BigDecimal.valueOf(
                                                 Double.parseDouble(t_datos.getValueAt(i, 16).toString()) / 0.9d)
                                                 .setScale(2, RoundingMode.UP).doubleValue();
                                         tabla.addCell(reporte.celda(
                                                 formatoPorcentaje.format(n * Double.parseDouble(
                                                         t_datos.getValueAt(i, renglon).toString())),
                                                 font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font,
                                                 contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         break;
                                     case 10:
                                         n = BigDecimal
                                                 .valueOf(
                                                         Double.parseDouble(t_datos.getValueAt(i, 15).toString())
                                                                 * 0.72d)
                                                 .setScale(2, RoundingMode.UP).doubleValue();
                                         tabla.addCell(reporte.celda(
                                                 formatoPorcentaje.format(n * Double.parseDouble(
                                                         t_datos.getValueAt(i, renglon).toString())),
                                                 font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font,
                                                 contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         break;
                                     case 11:
                                         n = BigDecimal
                                                 .valueOf(
                                                         Double.parseDouble(t_datos.getValueAt(i, 15).toString())
                                                                 * 0.65d)
                                                 .setScale(2, RoundingMode.UP).doubleValue();
                                         tabla.addCell(reporte.celda(
                                                 formatoPorcentaje.format(n * Double.parseDouble(
                                                         t_datos.getValueAt(i, renglon).toString())),
                                                 font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font,
                                                 contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         break;
                                     case 12:
                                         n = BigDecimal
                                                 .valueOf(
                                                         Double.parseDouble(t_datos.getValueAt(i, 15).toString())
                                                                 * 0.65d)
                                                 .setScale(2, RoundingMode.UP).doubleValue();
                                         tabla.addCell(reporte.celda(
                                                 formatoPorcentaje.format(n * Double.parseDouble(
                                                         t_datos.getValueAt(i, renglon).toString())),
                                                 font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font,
                                                 contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         break;
                                     }
                                 }
                                 //columna12
                                 if (t_datos.getValueAt(i, 18) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 18).toString(), font,
                                             contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                                 }

                                 //columna13
                                 if (t_datos.getValueAt(i, 19) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 19).toString(), font,
                                             contenido, centro, 0, 1, Rectangle.RECTANGLE));
                                 }
                                 //columna14
                                 tabla.addCell(
                                         reporte.celda("V", font, contenido, centro, 0, 1, Rectangle.RECTANGLE));
                             }
                         }
                     }
                 }
                 font1.setColor(BaseColor.WHITE);
                 tabla.addCell(reporte.celda("Faltante en Vales", font1, contenido1, centro, 15, 1,
                         Rectangle.RECTANGLE));

                 for (int i = 0; i < num_r; i++) {
                     for (int j = 0; j < 4; j++) {
                         int renglon = 0;
                         switch (j) {
                         case 0:
                             renglon = 8;
                             break;
                         case 1:
                             renglon = 10;
                             break;
                         case 2:
                             renglon = 11;
                             break;
                         case 3:
                             renglon = 12;
                             break;
                         }
                         if ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0
                                 && t_datos.getValueAt(i, 9).toString().compareTo("N") == 0)
                                 || ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0
                                         && renglon >= 10))
                                 || (renglon == 8
                                         && Double.parseDouble(t_datos.getValueAt(i, 10).toString()) <= 0
                                         && Double.parseDouble(t_datos.getValueAt(i, 11).toString()) <= 0
                                         && Double.parseDouble(t_datos.getValueAt(i, 12).toString()) <= 0)) {
                             if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0)
                                 contenido = BaseColor.WHITE;
                             else
                                 contenido = BaseColor.LIGHT_GRAY;

                             if ((boolean) t_datos.getValueAt(i, 3) == false
                                     && (boolean) t_datos.getValueAt(i, 4) == false
                                     && t_datos.getValueAt(i, 5) != null) {
                                 //columna0
                                 if (t_datos.getValueAt(i, 5) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 5).toString(), font,
                                             contenido, centro, 0, 1, Rectangle.RECTANGLE));
                                 }
                                 //columna1
                                 if (t_datos.getValueAt(i, 6) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 6).toString(), font,
                                             contenido, centro, 0, 1, Rectangle.RECTANGLE));
                                 }
                                 //columna2
                                 tabla.addCell(reporte.celda(t_datos.getValueAt(i, renglon).toString(), font,
                                         contenido, centro, 0, 1, Rectangle.RECTANGLE));

                                 //columna3
                                 if (t_datos.getValueAt(i, 14) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 14).toString(), font,
                                             contenido, centro, 0, 1, Rectangle.RECTANGLE));
                                 }
                                 //columna4
                                 tabla.addCell(reporte.celda(t_datos.getValueAt(i, 2).toString(), font,
                                         contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                                 //columna5
                                 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0)
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 else {
                                     switch (renglon) {
                                     case 8:
                                         tabla.addCell(reporte.celda("N", font, contenido, centro, 0, 1,
                                                 Rectangle.RECTANGLE));
                                         break;
                                     case 10:
                                         tabla.addCell(reporte.celda("D", font, contenido, centro, 0, 1,
                                                 Rectangle.RECTANGLE));
                                         break;
                                     case 11:
                                         tabla.addCell(reporte.celda("R", font, contenido, centro, 0, 1,
                                                 Rectangle.RECTANGLE));
                                         break;
                                     case 12:
                                         tabla.addCell(reporte.celda("M", font, contenido, centro, 0, 1,
                                                 Rectangle.RECTANGLE));
                                         break;
                                     }
                                 }
                                 //columna6
                                 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 15)),
                                         font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                 //columna7 $tot aut.
                                 double n;
                                 n = BigDecimal
                                         .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString())
                                                 * Double.parseDouble(t_datos.getValueAt(i, 15).toString()))
                                         .setScale(2, RoundingMode.UP).doubleValue();
                                 tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido,
                                         derecha, 0, 1, Rectangle.RECTANGLE));
                                 //columna8
                                 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 16)),
                                         font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                                 //columna9 $tot com
                                 n = BigDecimal
                                         .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString())
                                                 * Double.parseDouble(t_datos.getValueAt(i, 16).toString()))
                                         .setScale(2, RoundingMode.UP).doubleValue();
                                 tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido,
                                         derecha, 0, 1, Rectangle.RECTANGLE));

                                 //columna10 11
                                 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     switch (renglon) {
                                     case 8:
                                         n = BigDecimal.valueOf(
                                                 Double.parseDouble(t_datos.getValueAt(i, 16).toString()) / 0.9d)
                                                 .setScale(2, RoundingMode.UP).doubleValue();
                                         tabla.addCell(reporte.celda(
                                                 formatoPorcentaje.format(n * Double.parseDouble(
                                                         t_datos.getValueAt(i, renglon).toString())),
                                                 font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font,
                                                 contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         break;
                                     case 10:
                                         n = BigDecimal
                                                 .valueOf(
                                                         Double.parseDouble(t_datos.getValueAt(i, 15).toString())
                                                                 * 0.72d)
                                                 .setScale(2, RoundingMode.UP).doubleValue();
                                         tabla.addCell(reporte.celda(
                                                 formatoPorcentaje.format(n * Double.parseDouble(
                                                         t_datos.getValueAt(i, renglon).toString())),
                                                 font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font,
                                                 contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         break;
                                     case 11:
                                         n = BigDecimal
                                                 .valueOf(
                                                         Double.parseDouble(t_datos.getValueAt(i, 15).toString())
                                                                 * 0.65d)
                                                 .setScale(2, RoundingMode.UP).doubleValue();
                                         tabla.addCell(reporte.celda(
                                                 formatoPorcentaje.format(n * Double.parseDouble(
                                                         t_datos.getValueAt(i, renglon).toString())),
                                                 font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font,
                                                 contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         break;
                                     case 12:
                                         n = BigDecimal
                                                 .valueOf(
                                                         Double.parseDouble(t_datos.getValueAt(i, 15).toString())
                                                                 * 0.65d)
                                                 .setScale(2, RoundingMode.UP).doubleValue();
                                         tabla.addCell(reporte.celda(
                                                 formatoPorcentaje.format(n * Double.parseDouble(
                                                         t_datos.getValueAt(i, renglon).toString())),
                                                 font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font,
                                                 contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                         break;
                                     }
                                 }
                                 //columna12
                                 if (t_datos.getValueAt(i, 18) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 18).toString(), font,
                                             contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                                 }

                                 //columna13
                                 if (t_datos.getValueAt(i, 19) == null) {
                                     tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1,
                                             Rectangle.RECTANGLE));
                                 } else {
                                     tabla.addCell(reporte.celda(t_datos.getValueAt(i, 19).toString(), font,
                                             contenido, centro, 0, 1, Rectangle.RECTANGLE));
                                 }
                                 //columna14
                                 tabla.addCell(
                                         reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE));
                             }
                         }
                     }
                 }
                 tabla.addCell(reporte.celda("Total", font, contenido, derecha, 11, 1, Rectangle.NO_BORDER));
                 tabla.addCell(
                         reporte.celda(formatoPorcentaje.format(Double.parseDouble(total.getValue().toString())),
                                 font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                 tabla.addCell(reporte.celda(" ", font, contenido, centro, 3, 1, Rectangle.NO_BORDER));
                 tabla.setHeaderRows(1);
                 reporte.agregaObjeto(tabla);
                 reporte.cerrar();
                 reporte.visualizar2(ruta + ".pdf");
             }
         }
     } catch (Exception e) {
         e.printStackTrace();
     }
 }

From source file:Almacen.Conciliacion.java

private static void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo, int op) {

     com.itextpdf.text.Font font = new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 7,
             com.itextpdf.text.Font.BOLD);
     font.setColor(BaseColor.WHITE);// w  ww  . ja v  a 2s . c o  m
     BaseColor cabecera = BaseColor.DARK_GRAY;
     int centro = com.itextpdf.text.Element.ALIGN_CENTER;
     tabla.addCell(reporte.celda("N.SET", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("N.EXT", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("CNT", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("NPARTE", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("DESCRIPCIN", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("ORI", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("$C/U AUT", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("$TOT AUT", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("$C/U COM", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("$TOT COM", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("$C/U FAC", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("$TOT FAC", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("PROVEEDOR", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("#FACTURA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
     tabla.addCell(reporte.celda("VAL", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
 }

From source file:Almacen.Existencias.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    aux = 0;/*from w  ww  . j  a va  2 s .com*/
    try {
        javax.swing.JFileChooser archivo = new javax.swing.JFileChooser();
        archivo.setFileFilter(new ExtensionFileFilter("pdf document (*.pdf)", new String[] { "PDF" }));
        String ruta = null;
        if (archivo.showSaveDialog(null) == archivo.APPROVE_OPTION) {
            ruta = archivo.getSelectedFile().getAbsolutePath();
            if (ruta != null) {
                try {
                    PDF reporte = new PDF();
                    reporte.Abrir2(PageSize.LEGAL.rotate(), "Existencias", ruta + ".pdf");
                    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
                            BaseFont.NOT_EMBEDDED);
                    float[] tamanio = new float[] { 90, 120, 120, 55, 230, 55, 90, 90 };
                    Font font = new Font(Font.FontFamily.HELVETICA, 9, Font.NORMAL);
                    BaseColor contenido = BaseColor.WHITE;
                    int centro = com.itextpdf.text.Element.ALIGN_CENTER;
                    int izquierda = com.itextpdf.text.Element.ALIGN_LEFT;
                    int derecha = com.itextpdf.text.Element.ALIGN_RIGHT;

                    PdfPTable tabla = reporte.crearTabla(tamanio.length, tamanio, 100, Element.ALIGN_CENTER);
                    cabecera(reporte, bf, tabla, "EXISTENCIAS DE ARTICULOS.", 2);

                    for (int i = 0; i < t_datos.getRowCount(); i++) {
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 0).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 1).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 2).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 4).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 5).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 6).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 7).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                    }
                    reporte.agregaObjeto(tabla);
                    reporte.cerrar();
                    reporte.visualizar2(ruta + ".pdf");
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(this,
                            "No se pudo realizar el reporte si el archivo esta abierto.");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Almacen.Existencias.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // TODO add your handling code here:
    aux = 1;//from w  w w. j ava2s. c  o m
    try {
        javax.swing.JFileChooser archivo = new javax.swing.JFileChooser();
        archivo.setFileFilter(new ExtensionFileFilter("pdf document (*.pdf)", new String[] { "PDF" }));
        String ruta = null;
        if (archivo.showSaveDialog(null) == archivo.APPROVE_OPTION) {
            ruta = archivo.getSelectedFile().getAbsolutePath();
            if (ruta != null) {
                try {
                    PDF reporte = new PDF();
                    reporte.Abrir2(PageSize.LEGAL.rotate(), "Existencias", ruta + ".pdf");
                    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
                            BaseFont.NOT_EMBEDDED);
                    float[] tamanio = new float[] { 90, 120, 120, 55, 230, 55, 100, 100 };
                    Font font = new Font(Font.FontFamily.HELVETICA, 9, Font.NORMAL);
                    BaseColor contenido = BaseColor.WHITE;
                    int centro = com.itextpdf.text.Element.ALIGN_CENTER;
                    int izquierda = com.itextpdf.text.Element.ALIGN_LEFT;
                    int derecha = com.itextpdf.text.Element.ALIGN_RIGHT;

                    PdfPTable tabla = reporte.crearTabla(tamanio.length, tamanio, 100, Element.ALIGN_CENTER);
                    cabecera(reporte, bf, tabla, "EXISTENCIAS DE ARTICULOS.", 2);

                    for (int i = 0; i < t_datos.getRowCount(); i++) {
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 0).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 1).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 2).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 4).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 5).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(t_datos.getValueAt(i, 6).toString(), font, contenido,
                                centro, 0, 1, Rectangle.RECTANGLE));
                        tabla.addCell(reporte.celda(" ", font, contenido, centro, 0, 1, Rectangle.RECTANGLE));
                    }
                    reporte.agregaObjeto(tabla);
                    reporte.cerrar();
                    reporte.visualizar2(ruta + ".pdf");
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(this,
                            "No se pudo realizar el reporte si el archivo esta abierto.");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Almacen.Existencias.java

public void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo, int op) {
    reporte.inicioTexto();//from   www. j av  a 2 s.c  o  m
    reporte.contenido.setFontAndSize(bf, 9);
    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 495, 0);
    reporte.finTexto();

    reporte.agregaObjeto(reporte.crearImagen("imagenes/factura300115.jpg", 250, -52, 60));
    reporte.agregaObjeto(new Paragraph(" "));
    reporte.agregaObjeto(new Paragraph(" "));
    reporte.agregaObjeto(new Paragraph(" "));
    reporte.agregaObjeto(new Paragraph(" "));
    reporte.agregaObjeto(new Paragraph(" "));
    Font font = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD);

    BaseColor cabecera = BaseColor.GRAY;
    BaseColor contenido = BaseColor.WHITE;
    int centro = com.itextpdf.text.Element.ALIGN_CENTER;
    int izquierda = com.itextpdf.text.Element.ALIGN_LEFT;
    int derecha = com.itextpdf.text.Element.ALIGN_RIGHT;
    tabla.addCell(reporte.celda("ID PARTE", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("MARCA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("TIPO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("MODELO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("CATALOGO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("MEDIDA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("EXIST. SISTEMA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    if (aux != 0)
        tabla.addCell(reporte.celda("EXIST. FISICO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    else
        tabla.addCell(reporte.celda("COMENTARIO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
}

From source file:Almacen.formatosAlmacen.java

void formato() {
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//  w w w.j a  v  a2  s . c  om
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        miAlmacen = (Almacen) session.get(Almacen.class, miAlmacen.getIdAlmacen());
        DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
        formatoPorcentaje.setMinimumFractionDigits(2);

        session.beginTransaction().begin();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);

        PDF reporte = new PDF();
        Date fecha = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);
        Movimiento[] mov = (Movimiento[]) session.createCriteria(Movimiento.class)
                .add(Restrictions.eq("almacen.idAlmacen", miAlmacen.getIdAlmacen())).list()
                .toArray(new Movimiento[0]);
        Orden ord = null;
        if (mov.length > 0)
            ord = mov[0].getPartida().getOrdenByIdOrden();
        //File folder = new File("reportes/"+ord.getIdOrden());
        //folder.mkdirs();
        reporte.Abrir(PageSize.LETTER, "Almacen",
                "reportes/" + ord.getIdOrden() + "/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf");
        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        float tam[] = new float[] { 20, 20, 80, 190, 20, 30, 50, 50 };
        PdfPTable tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT);

        cabeceraCompra(reporte, bf, tabla, miAlmacen, ord);

        int ren = 0;
        double total = 0d;
        if (mov.length > 0) {
            for (int i = 0; i < mov.length; i++) {
                int r = i + 1;
                //N
                tabla.addCell(reporte.celda("" + mov[i].getPartida().getIdEvaluacion(), font, contenido,
                        izquierda, 0, 1, Rectangle.RECTANGLE));

                //#
                tabla.addCell(reporte.celda("" + mov[i].getPartida().getSubPartida(), font, contenido, derecha,
                        0, 1, Rectangle.RECTANGLE));

                if (mov[i].getPartida().getEjemplar() != null) {
                    //No de parte
                    tabla.addCell(reporte.celda("" + mov[i].getPartida().getEjemplar().getIdParte(), font,
                            contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                } else
                    tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                //Descripcion
                tabla.addCell(reporte.celda(mov[i].getPartida().getCatalogo().getNombre(), font, contenido,
                        izquierda, 0, 1, Rectangle.RECTANGLE));

                //med
                tabla.addCell(reporte.celda(mov[i].getPartida().getMed(), font, contenido, izquierda, 0, 1,
                        Rectangle.RECTANGLE));

                //cant 
                tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido,
                        derecha, 0, 1, Rectangle.RECTANGLE));

                tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getPartida().getPcp()), font,
                        contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                double sum = mov[i].getCantidad() * mov[i].getPartida().getPcp();
                total += sum;
                tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0, 1,
                        Rectangle.RECTANGLE));

                if (ren == 38) {
                    reporte.agregaObjeto(tabla);
                    reporte.writer.newPage();
                    tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT);
                    cabeceraCompra(reporte, bf, tabla, miAlmacen, ord);
                    ren = -1;
                }
                ren++;
            }
        }
        tabla.addCell(reporte.celda("Notas:", font, contenido, izquierda, 0, 1, Rectangle.BOTTOM));
        tabla.addCell(reporte.celda(miAlmacen.getNotas(), font, contenido, izquierda, 7, 1, Rectangle.BOTTOM));
        if (miAlmacen.getTipoMovimiento() == 1)
            tabla.addCell(reporte.celda("Entrego: " + miAlmacen.getEntrego(), font, contenido, izquierda, 3, 1,
                    Rectangle.NO_BORDER));
        else
            tabla.addCell(reporte.celda("recibi:" + miAlmacen.getEntrego(), font, contenido, izquierda, 3, 1,
                    Rectangle.NO_BORDER));
        tabla.addCell(reporte.celda("Sub-total:", font, contenido, derecha, 4, 1, Rectangle.NO_BORDER));
        tabla.addCell(reporte.celda(formatoPorcentaje.format(total), font, contenido, derecha, 0, 1,
                Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("IVA:", font, contenido, derecha, 7, 1, Rectangle.NO_BORDER));
        double iva = total * 0.16d;
        tabla.addCell(reporte.celda(formatoPorcentaje.format(iva), font, contenido, derecha, 0, 1,
                Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Total:", font, contenido, derecha, 7, 1, Rectangle.NO_BORDER));
        total += iva;
        tabla.addCell(reporte.celda(formatoPorcentaje.format(total), font, contenido, derecha, 0, 1,
                Rectangle.RECTANGLE));
        session.beginTransaction().rollback();

        reporte.agregaObjeto(tabla);
        reporte.cerrar();
        reporte.visualizar(
                "reportes/" + ord.getIdOrden() + "/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf");

    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, "No se pudo realizar el reporte si el archivo esta abierto.");
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}