Example usage for com.itextpdf.text.pdf BaseFont HELVETICA

List of usage examples for com.itextpdf.text.pdf BaseFont HELVETICA

Introduction

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

Prototype

String HELVETICA

To view the source code for com.itextpdf.text.pdf BaseFont HELVETICA.

Click Source Link

Document

This is a possible value of a base 14 type 1 font

Usage

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 v  a  2  s. co m
         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.Existencias.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    aux = 0;//from ww w.  j  a  va 2  s .  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, 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;//  w w  w  . j  av a 2s . 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.formatosAlmacen.java

void formato() {
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//  www . j  ava 2s. c o  m
    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();
}

From source file:Almacen.formatosOrden.java

void formato() {
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/*from  w  w  w. j a va2  s.  c o m*/
    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) {
            if (mov[0].getPartida() != null) {
                ord = mov[0].getPartida().getOrdenByIdOrden();
            } else {
                ord = mov[0].getPartidaExterna().getPedido().getOrden();
                //ord=miAlmacen.getPedido().getPartida().getOrdenByIdOrden();
                //ord=mov[0].getOrden();
            }
        }
        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 };
        PdfPTable tabla = reporte.crearTabla(6, tam, 100, Element.ALIGN_LEFT);
        cabeceraCompra(reporte, bf, tabla, miAlmacen, ord);
        int ren = 0;
        double total = 0d;
        if (mov.length > 0) {
            int renglon = 0;
            for (int i = 0; i < mov.length; i++) {
                int r = i + 1;
                renglon++;
                if (mov[i].getPartida() != null) {
                    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)
                        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));
                    tabla.addCell(reporte.celda(mov[i].getPartida().getCatalogo().getNombre(), font, contenido,
                            izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(mov[i].getPartida().getMed(), font, contenido, izquierda, 0, 1,
                            Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido,
                            derecha, 0, 1, Rectangle.RECTANGLE));
                } else {
                    tabla.addCell(reporte.celda("-", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                    if (mov[i].getPartidaExterna().getNoParte() != null)
                        tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getNoParte(), font, contenido,
                                derecha, 0, 1, Rectangle.RECTANGLE));
                    else
                        tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getDescripcion(), font, contenido,
                            izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getUnidad(), font, contenido,
                            izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido,
                            derecha, 0, 1, Rectangle.RECTANGLE));
                }
                if (ren == 20)//20
                {
                    reporte.writer.newPage();
                    reporte.agregaObjeto(tabla);
                    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(" "));
                    reporte.agregaObjeto(new Paragraph(" "));
                    reporte.agregaObjeto(tabla);
                    reporte.agregaObjeto(new Paragraph(" "));
                    reporte.agregaObjeto(new Paragraph(" "));
                    reporte.agregaObjeto(new Paragraph(" "));
                    reporte.agregaObjeto(new Paragraph(" "));

                    tabla = reporte.crearTabla(6, tam, 100, Element.ALIGN_LEFT);
                    cabeceraCompra(reporte, bf, tabla, miAlmacen, ord);
                    ren = -1;
                    renglon = 0;
                }
                ren++;
            }
            for (renglon = renglon; renglon < 20; renglon++) {
                tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            }
        }
        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));
        session.beginTransaction().rollback();

        reporte.agregaObjeto(tabla);
        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(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        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();
}

From source file:Almacen.formatosPedido.java

void formato() {
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/*from   ww  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;
        OrdenExterna ordEx = null;
        if (mov.length > 0) {
            if (miAlmacen.getOperacion() == 1)
                ord = mov[0].getPartida().getOrdenByIdOrden();
            /*if(miAlmacen.getOperacion()==2)
            ordEx=miAlmacen.getPedido().getOrdenExterna();*/
            if (miAlmacen.getOperacion() == 3)
                ord = miAlmacen.getPedido().getOrden();
            //ord=miAlmacen.getPedido().getPartida().getOrdenByIdOrden();
        }
        File folder = new File("reportes");
        folder.mkdirs();
        reporte.Abrir(PageSize.LETTER, "Almacen",
                "reportes/" + 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[];
        PdfPTable tabla;
        if (miAlmacen.getOperacion() != 6) {
            tam = new float[] { 20, 20, 80, 190, 20, 30, 50, 50 };
            tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT);
        } else {
            tam = new float[] { 20, 20, 80, 190, 20, 30 };
            tabla = reporte.crearTabla(6, tam, 100, Element.ALIGN_LEFT);
        }

        cabeceraCompra(reporte, bf, tabla, miAlmacen, ord);
        int ren = 0;
        double total = 0d;
        if (mov.length > 0) {
            int renglon = 0;
            for (int i = 0; i < mov.length; i++) {
                if (miAlmacen.getOperacion() == 1) {
                    int r = i + 1;
                    renglon++;
                    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)
                        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));
                    tabla.addCell(reporte.celda(mov[i].getPartida().getCatalogo().getNombre(), font, contenido,
                            izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(mov[i].getPartida().getMed(), font, contenido, izquierda, 0, 1,
                            Rectangle.RECTANGLE));
                    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 == 20)//20
                    {
                        reporte.writer.newPage();
                        reporte.agregaObjeto(tabla);
                        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(" "));
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(tabla);
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(new Paragraph(" "));

                        tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT);
                        cabeceraCompra(reporte, bf, tabla, miAlmacen, ord);
                        ren = -1;
                        renglon = 0;
                    }
                    ren++;
                }
                if (miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 6) {
                    int r = i + 1;
                    renglon++;

                    tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                    if (mov[i].getPartidaExterna().getNoParte() != null)
                        tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getNoParte(), font, contenido,
                                derecha, 0, 1, Rectangle.RECTANGLE));
                    else
                        tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getDescripcion(), font, contenido,
                            izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getUnidad(), font, contenido,
                            izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido,
                            derecha, 0, 1, Rectangle.RECTANGLE));
                    if (miAlmacen.getOperacion() == 2) {
                        tabla.addCell(
                                reporte.celda(formatoPorcentaje.format(mov[i].getPartidaExterna().getCosto()),
                                        font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                        double sum = mov[i].getCantidad() * mov[i].getPartidaExterna().getCosto();
                        total += sum;
                        tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0,
                                1, Rectangle.RECTANGLE));
                    }
                    if (ren == 20)//20
                    {
                        reporte.writer.newPage();
                        reporte.agregaObjeto(tabla);
                        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(" "));
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(tabla);
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(new Paragraph(" "));

                        tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT);
                        cabeceraCompra(reporte, bf, tabla, miAlmacen, ord);
                        ren = -1;
                        renglon = 0;
                    }
                    ren++;
                }
                if (miAlmacen.getOperacion() == 3) {
                    int r = i + 1;
                    renglon++;
                    //tabla.addCell(reporte.celda(""+miAlmacen.getPedido().getPartida().getIdEvaluacion(), font, contenido, izquierda, 0,1,Rectangle.RECTANGLE));
                    //tabla.addCell(reporte.celda(""+miAlmacen.getPedido().getPartida().getSubPartida(), font, contenido, derecha, 0,1,Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                    if (mov[i].getPartidaExterna().getNoParte() != null)
                        tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getNoParte(), font, contenido,
                                derecha, 0, 1, Rectangle.RECTANGLE));
                    else
                        tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                    //tabla.addCell(reporte.celda(miAlmacen.getPedido().getPartida().getCatalogo().getNombre()+"/"+mov[i].getPartidaExterna().getDescripcion(), font, contenido, izquierda, 0,1,Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getDescripcion(), font, contenido,
                            izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getUnidad(), font, contenido,
                            izquierda, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido,
                            derecha, 0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getPartidaExterna().getCosto()),
                            font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                    double sum = mov[i].getCantidad() * mov[i].getPartidaExterna().getCosto();
                    total += sum;
                    tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0, 1,
                            Rectangle.RECTANGLE));

                    if (ren == 20)//20
                    {
                        reporte.writer.newPage();
                        reporte.agregaObjeto(tabla);
                        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(" "));
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(tabla);
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(new Paragraph(" "));
                        reporte.agregaObjeto(new Paragraph(" "));

                        tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT);
                        cabeceraCompra(reporte, bf, tabla, miAlmacen, ord);
                        ren = -1;
                        renglon = 0;
                    }
                    ren++;
                }
            }
            for (renglon = renglon; renglon < 20; renglon++) {
                tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
            }
        }
        tabla.addCell(reporte.celda("Notas: ", font, contenido, izquierda, 0, 1, Rectangle.BOTTOM));
        tabla.addCell(reporte.celda(miAlmacen.getNotas(), font, contenido, izquierda,
                tabla.getNumberOfColumns() - 1, 1, Rectangle.BOTTOM));

        if (miAlmacen.getOperacion() != 6) {
            tabla.addCell(reporte.celda("", 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));
            Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
            double iva = total * con.getIva() / 100;
            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));
        } else {
            tabla.addCell(reporte.celda("", font, contenido, izquierda, 8, 1, Rectangle.NO_BORDER));
            tabla.addCell(reporte.celda("", font, contenido, derecha, 8, 1, Rectangle.NO_BORDER));
            tabla.addCell(reporte.celda("", font, contenido, derecha, 8, 1, Rectangle.RECTANGLE));
        }
        session.beginTransaction().rollback();
        reporte.agregaObjeto(tabla);
        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(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(tabla);
        reporte.cerrar();
        reporte.visualizar("reportes/" + 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();
}

From source file:Almacen.Reporte2.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/*from w ww  .ja v a2s  .co  m*/
    if (t_datos1.getRowCount() > 0) {
        javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
        jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" }));
        String ruta = null;
        if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
            ruta = jF1.getSelectedFile().getAbsolutePath();
            if (ruta != null) {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try {
                    DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
                    formatoPorcentaje.setMinimumFractionDigits(2);
                    session.beginTransaction().begin();
                    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
                            BaseFont.NOT_EMBEDDED);
                    //Orden ord=buscaApertura();
                    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);

                    reporte.Abrir2(PageSize.LETTER, "reporte almacen", ruta + ".pdf");
                    Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL);
                    BaseColor contenido = BaseColor.WHITE;
                    int centro = Element.ALIGN_CENTER;
                    int izquierda = Element.ALIGN_LEFT;
                    int derecha = Element.ALIGN_RIGHT;
                    float[] nuevos = new float[] { 20, 150, 20, 100, 70, 20, 60 };

                    PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_LEFT);

                    cabecera(reporte, bf, tabla, "Reporte de material a " + cb_tipo.getSelectedItem().toString()
                            + " orden: " + t_busca.getText(), 2);
                    for (int ren = 0; ren < t_datos1.getRowCount(); ren++) {
                        for (int col = 0; col < t_datos1.getColumnCount(); col++) {
                            try {
                                tabla.addCell(reporte.celda(t_datos1.getValueAt(ren, col).toString(), font,
                                        contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                            } catch (Exception e) {
                                tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1,
                                        Rectangle.RECTANGLE));
                            }
                        }
                    }
                    tabla.setHeaderRows(1);
                    reporte.agregaObjeto(tabla);
                    reporte.cerrar();
                    reporte.visualizar2(ruta + ".pdf");
                } catch (Exception e) {
                    System.out.println(e);
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this,
                            "No se pudo realizar el reporte si el archivo esta abierto.");
                }
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        }
    }
}

From source file:Almacen.Reporte2.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//from   w  w w.j  a va 2 s  . com
    if (t_datos.getRowCount() > 0) {
        javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
        jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" }));
        String ruta = null;
        if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
            ruta = jF1.getSelectedFile().getAbsolutePath();
            if (ruta != null) {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try {
                    DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
                    formatoPorcentaje.setMinimumFractionDigits(2);
                    session.beginTransaction().begin();
                    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
                            BaseFont.NOT_EMBEDDED);
                    //Orden ord=buscaApertura();
                    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);

                    reporte.Abrir2(PageSize.LETTER, "reporte almacen", ruta + ".pdf");
                    Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL);
                    BaseColor contenido = BaseColor.WHITE;
                    int centro = Element.ALIGN_CENTER;
                    int izquierda = Element.ALIGN_LEFT;
                    int derecha = Element.ALIGN_RIGHT;
                    float[] nuevos = new float[] { 36, 140, 86, 36, 40, 45, 37, 50, 42, 60 };

                    PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_LEFT);

                    cabecera(reporte, bf, tabla, "Reporte de movimientos de pedidos en almacen", 1);
                    for (int ren = 0; ren < t_datos.getRowCount(); ren++) {
                        for (int col = 0; col < t_datos.getColumnCount(); col++) {
                            try {
                                if (col == 7)
                                    tabla.addCell(reporte.celda(
                                            formatoPorcentaje.format(t_datos.getValueAt(ren, col)), font,
                                            contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                else
                                    tabla.addCell(reporte.celda(t_datos.getValueAt(ren, col).toString(), font,
                                            contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
                            } catch (Exception e) {
                                tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1,
                                        Rectangle.RECTANGLE));
                            }
                        }
                    }
                    tabla.setHeaderRows(1);
                    reporte.agregaObjeto(tabla);
                    reporte.cerrar();
                    reporte.visualizar2(ruta + ".pdf");
                } catch (Exception e) {
                    System.out.println(e);
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this,
                            "No se pudo realizar el reporte si el archivo esta abierto.");
                }
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        }
    }
}

From source file:Almacen.Reporte2.java

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/* w  w w.j  av a2 s . c  o m*/
    if (t_datos2.getRowCount() > 0) {
        javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
        jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" }));
        String ruta = null;
        if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
            ruta = jF1.getSelectedFile().getAbsolutePath();
            if (ruta != null) {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try {
                    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);

                    reporte.Abrir2(PageSize.LETTER, "reporte pedidos", ruta + ".pdf");
                    Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL);
                    BaseColor contenido = BaseColor.WHITE;
                    int centro = Element.ALIGN_CENTER;
                    int izquierda = Element.ALIGN_LEFT;
                    int derecha = Element.ALIGN_RIGHT;
                    float[] nuevos = new float[] { 60, 340, 170, 60, 90, 90, 90 };

                    PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_CENTER);
                    cabecera1(reporte, bf, tabla, "Reporte de Consultar Pedidos.", 1);
                    for (int ren = 0; ren < t_datos2.getRowCount(); ren++) {
                        for (int col = 0; col < t_datos2.getColumnCount(); col++) {
                            try {
                                tabla.addCell(reporte.celda(t_datos2.getValueAt(ren, col).toString(), font,
                                        contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                            } catch (Exception e) {
                                tabla.addCell(
                                        reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE));
                            }
                        }
                    }
                    tabla.setHeaderRows(1);
                    reporte.agregaObjeto(tabla);
                    reporte.cerrar();
                    reporte.visualizar2(ruta + ".pdf");
                } catch (Exception e) {
                    System.out.println(e);
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this,
                            "No se pudo realizar el reporte si el archivo esta abierto.");
                }
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        }
    }
}

From source file:Almacen.Responsiva.java

private void b_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_imprimirActionPerformed
    // TODO add your handling code here:
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*  ww w  .  j  a v  a2 s  . co m*/
        String empleado = "";
        String puesto = "";
        if (t_datos.getRowCount() > 0) {
            //consulta
            Query q = session.createSQLQuery(
                    "select empleado.nombre as empleado, puestos.nombre as puesto from empleado inner join puestos on puestos.id_puestos=empleado.id_puesto where empleado.id_empleado="
                            + t_id_empleado.getText() + ";");
            q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
            List lista = q.list();

            for (int i = 0; i < lista.size(); i++) {
                java.util.HashMap map = (java.util.HashMap) lista.get(i);
                empleado = (String) map.get("empleado");
                puesto = (String) map.get("puesto");
            }

            Date fecha = new Date();
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
            String Mes[] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto",
                    "Septiembre", "Octubre", "Noviembre", "Diciembre" };
            Calendar fecha1 = new GregorianCalendar();
            int anio = fecha1.get(Calendar.YEAR);
            int mes = fecha1.get(Calendar.MONTH);
            int dia = fecha1.get(Calendar.DAY_OF_MONTH);
            //DateFormat dateFormat1 = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
            String valor = dateFormat.format(fecha);
            File folder = new File("reportes/Responsivas");
            folder.mkdirs();
            PdfReader reader = new PdfReader("imagenes/CartaResponsiva.pdf");
            PdfStamper stamp = new PdfStamper(reader,
                    new FileOutputStream("reportes/Responsivas/" + valor + "CartaResponsiva.pdf"));
            PdfContentByte cb = stamp.getUnderContent(1);
            PdfContentByte cb2 = stamp.getUnderContent(2);
            AcroFields fdfDoc = stamp.getAcroFields();
            // Creo una fuente
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

            cb.beginText();
            //dia
            try {
                if (dia < 9)
                    fdfDoc.setField("Dia", "0" + String.valueOf(dia));
                else
                    fdfDoc.setField("Dia", String.valueOf(dia));
            } catch (Exception e) {
                fdfDoc.setField("Dia", "error");
            }
            //mes
            try {
                fdfDoc.setField("Mes", Mes[mes]);
            } catch (Exception e) {
                fdfDoc.setField("Mes", "");
            }
            //ao
            try {
                fdfDoc.setField("Anio", String.valueOf(anio));
            } catch (Exception e) {
                fdfDoc.setField("Anio", "");
            }
            //nombre
            try {
                fdfDoc.setField("Nombre", empleado);
            } catch (Exception e) {
                fdfDoc.setField("Nombre", "");
            }
            //puesto
            try {
                fdfDoc.setField("Puesto", puesto);
            } catch (Exception e) {
                fdfDoc.setField("Puesto", "");
            }

            //tabla de herramientas
            float tam[] = new float[] { 250, 50, 180 };
            Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
            PDF reporte = new PDF();
            PdfPTable tabla = reporte.crearTabla(3, tam, 100, Element.ALIGN_LEFT);
            tabla.setTotalWidth(tam);
            BaseColor cabecera = BaseColor.GRAY;
            BaseColor contenido = BaseColor.WHITE;
            int centro = Element.ALIGN_CENTER;
            int izquierda = Element.ALIGN_LEFT;
            int derecha = Element.ALIGN_RIGHT;

            tabla.addCell(reporte.celda("HERRAMIENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("CANTIDAD", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("NOTAS", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));

            for (int i = 0; i < t_datos.getRowCount(); i++) {
                tabla.addCell(reporte.celda(t_datos.getValueAt(i, 1).toString(), font, contenido, izquierda, 0,
                        1, Rectangle.RECTANGLE));

                tabla.addCell(reporte.celda(String.valueOf((double) t_datos.getValueAt(i, 2)), font, contenido,
                        centro, 0, 1, Rectangle.RECTANGLE));
                if (t_datos.getValueAt(i, 3) != null)
                    tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido, izquierda,
                            0, 1, Rectangle.RECTANGLE));
                else
                    tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
            }

            tabla.completeRow();
            tabla.writeSelectedRows(0, -1, 70, 720, cb2);
            cb.endText();
            stamp.close();
            reporte.cerrar();
            reporte.visualizar("reportes/Responsivas/" + valor + "CartaResponsiva.pdf");
        } else {
            JOptionPane.showMessageDialog(this, "No Existe Ninguna Responsiva");
        }
    } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto");
    }
    if (session != null) {
        if (session.isOpen()) {
            session.close();
        }
    }
}