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:Almacen.formatosAlmacen.java

private void cabeceraCompra(PDF reporte, BaseFont bf, PdfPTable tabla, Almacen almacen, Orden ord) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*from ww w . ja va 2s .  c o m*/
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));
        if (almacen.getPedido() != null) {
            reporte.contenido.roundRectangle(35, 695, 180, 10, 0);
            reporte.contenido.roundRectangle(35, 625, 180, 80, 0);

            reporte.contenido.roundRectangle(215, 695, 180, 10, 0);
            reporte.contenido.roundRectangle(215, 625, 180, 80, 0);
        }
        reporte.contenido.roundRectangle(395, 695, 180, 10, 0);
        reporte.contenido.roundRectangle(395, 625, 180, 80, 0);

        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 13);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.agregaObjeto(reporte.crearImagen("imagenes/grande300115.jpg", 30, -40, 60));
        reporte.contenido.setFontAndSize(bf, 12);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        if (almacen.getPedido() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Movimiento en almacen: "
                    + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(), 35, 710, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "Movimiento en almacen: " + almacen.getIdAlmacen(), 35, 710, 0);
        reporte.contenido.setFontAndSize(bf, 7);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 570, 710, 0);

        ord = (Orden) session.get(Orden.class, ord.getIdOrden());

        //************************datos del proveedor****************************
        if (almacen.getPedido() != null) {
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "DATOS DEL PROVEEDOR", 73, 697, 0);

            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    almacen.getPedido().getProveedorByIdProveedor().getNombre(), 40, 687, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getDireccion() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        almacen.getPedido().getProveedorByIdProveedor().getDireccion(), 40, 677, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Dir:", 40, 677, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getColonia() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Col: " + almacen.getPedido().getProveedorByIdProveedor().getColonia(), 40, 667, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Col:", 40, 667, 0);

            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "Edo: " + almacen.getPedido().getProveedorByIdProveedor().getEstado(), 40, 657, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getTel1() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Tel: " + almacen.getPedido().getProveedorByIdProveedor().getTel1(), 40, 647, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tel:", 40, 647, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getTel1() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Cto: " + almacen.getPedido().getProveedorByIdProveedor().getRepresentante(), 40, 637,
                        0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Cto:", 40, 637, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getEmail() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Email: " + almacen.getPedido().getProveedorByIdProveedor().getEmail(), 40, 627, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Email: ", 40, 627, 0);

            //**********************datos de facturacion*****************************
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "DATOS DE FACTURACIN", 250, 697, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    almacen.getPedido().getProveedorByIdEmpresa().getNombre(), 220, 687, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getDireccion() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        almacen.getPedido().getProveedorByIdEmpresa().getDireccion(), 220, 677, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Dir:", 220, 677, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getColonia() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Col: " + almacen.getPedido().getProveedorByIdEmpresa().getColonia(), 220, 667, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Col:", 220, 667, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getPoblacion() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Pob: " + almacen.getPedido().getProveedorByIdEmpresa().getPoblacion(), 220, 657, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Pob:", 220, 657, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getCp() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "CP: " + almacen.getPedido().getProveedorByIdEmpresa().getCp(), 220, 647, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "CP:", 220, 647, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getRfc() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "RFC: " + almacen.getPedido().getProveedorByIdEmpresa().getRfc(), 220, 637, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RFC:", 220, 537, 0);
        }
        //**********************datos de la unidad*****************************
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "DATOS LA UNIDAD", 450, 697, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Orden: " + ord.getIdOrden(), 410, 687,
                0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo: " + ord.getTipo().getTipoNombre(),
                410, 677, 0);
        if (ord.getNoSerie() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Serie: " + ord.getNoSerie(), 410,
                    667, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Serie: ", 410, 667, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Modelo: " + ord.getModelo(), 410, 657, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "Compaia: " + ord.getCompania().getNombre(), 410, 647, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Cli:" + ord.getClientes().getNombre(),
                410, 637, 0);
        if (ord.getSiniestro() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Siniestro:" + ord.getSiniestro(),
                    410, 627, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Siniestro:", 410, 627, 0);

        reporte.finTexto();
        reporte.contenido.setFontAndSize(bf, 12);
        //agregamos renglones vacios para dejar un espacio
        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(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor cabecera = BaseColor.GRAY;
        int centro = Element.ALIGN_CENTER;

        tabla.addCell(reporte.celda("N", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("#", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("N Parte", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Descripcin", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Med", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Cant", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Costo c/u", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Total", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));

        reporte.contenido.roundRectangle(50, 40, 180, 1, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Almacen", 120, 30, 0);
        reporte.contenido.roundRectangle(370, 40, 180, 1, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Proveedor", 440, 30, 0);
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:Almacen.formatosOrden.java

void formato() {
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/*  ww  w . j a v  a  2  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.formatosOrden.java

private void cabeceraCompra(PDF reporte, BaseFont bf, PdfPTable tabla, Almacen almacen, Orden ord) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from  www. j  a v a  2  s  .  c o  m
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));
        reporte.contenido.roundRectangle(35, 755, 280, 10, 0);
        reporte.contenido.roundRectangle(35, 735, 280, 20, 0);
        ////*2
        reporte.contenido.roundRectangle(35, 388, 280, 10, 0);
        reporte.contenido.roundRectangle(35, 368, 280, 20, 0);
        ////         
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 13);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.agregaObjeto(reporte.crearImagen("imagenes/grande300115.jpg", 335, -23, 30));
        /*2*/reporte.agregarImagen(reporte.crearImagen("imagenes/grande300115.jpg", 100, -390, 30));
        reporte.contenido.setFontAndSize(bf, 12);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        if (miAlmacen.getTipoMovimiento() == 1) {
            if (miAlmacen.getOperacion() == 4)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos en Almacn (Entrada de Material): " + almacen.getIdAlmacen(), 35, 767, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos de Almacn (Devolucin de material de operarios): "
                                + almacen.getIdAlmacen(),
                        35, 767, 0);
            //*********2
            if (miAlmacen.getOperacion() == 4)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos en Almacn (Entrada de Material): " + almacen.getIdAlmacen(), 35, 400, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos de Almacn (Devolucin de material de operarios): "
                                + almacen.getIdAlmacen(),
                        35, 400, 0);
            ////
        } else {
            if (miAlmacen.getOperacion() == 4)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimiento de Almacn (Devolucin de material a proveedor): "
                                + almacen.getIdAlmacen(),
                        35, 767, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos de Almacn (Entrega de material a operarios): " + almacen.getIdAlmacen(),
                        35, 767, 0);
            //*********2
            if (miAlmacen.getOperacion() == 4)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimiento de Almacn (Devolucin de material a proveedor): "
                                + almacen.getIdAlmacen(),
                        35, 400, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos de Almacn (Entrega de material a operarios): " + almacen.getIdAlmacen(),
                        35, 400, 0);
            ///
        }

        reporte.contenido.setFontAndSize(bf, 7);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 306, 757, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 306, 390, 0);

        ord = (Orden) session.get(Orden.class, ord.getIdOrden());

        //************************datos de movimiento****************************
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Materiales y Refacciones del Almacn",
                40, 757, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "Materiales y Refacciones del Almacn", 40, 390, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "N. Movimiento: " + almacen.getIdAlmacen(), 40, 747, 0);
        /*2*/ reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "N. Movimiento: " + almacen.getIdAlmacen(), 40, 380, 0);
        if (almacen.getTipoMovimiento() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Entrada", 120,
                    747, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Salida", 120,
                    747, 0);
        ////**2
        if (almacen.getTipoMovimiento() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Entrada", 120,
                    380, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Salida", 120,
                    380, 0);
        ////

        if (almacen.getOperacion() == 4)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Compaa", 220,
                    747, 0);
        if (almacen.getOperacion() == 5)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Operarios", 220,
                    747, 0);

        ////**2
        if (almacen.getOperacion() == 4)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Compaa", 220,
                    380, 0);
        if (almacen.getOperacion() == 5)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Operarios", 220,
                    380, 0);
        ////

        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N. Orden: " + ord.getIdOrden(), 40, 737,
                0);
        /*2*/ reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N. Orden: " + ord.getIdOrden(),
                40, 370, 0);

        //Firmas de material 
        if (miAlmacen.getTipoMovimiento() == 1) {
            reporte.contenido.roundRectangle(45, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ENTREGA: " + almacen.getEntrego(), 45,
                    440, 0);
            reporte.contenido.roundRectangle(250, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 440, 0);
            reporte.contenido.roundRectangle(440, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "RECIBE: " + almacen.getUsuario().getEmpleado().getNombre(), 440, 440, 0);
        } else {
            reporte.contenido.roundRectangle(45, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "ENTREGA: " + almacen.getUsuario().getEmpleado().getNombre(), 45, 440, 0);
            reporte.contenido.roundRectangle(250, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 440, 0);
            reporte.contenido.roundRectangle(440, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RECIBE: " + almacen.getEntrego(), 440,
                    440, 0);
        }

        /*2*/if (miAlmacen.getTipoMovimiento() == 1) {
            reporte.contenido.roundRectangle(45, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ENTREGA: " + almacen.getEntrego(), 45,
                    20, 0);
            reporte.contenido.roundRectangle(250, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 20, 0);
            reporte.contenido.roundRectangle(440, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "RECIBE: " + almacen.getUsuario().getEmpleado().getNombre(), 440, 20, 0);
        } else {
            reporte.contenido.roundRectangle(45, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "ENTREGA: " + almacen.getUsuario().getEmpleado().getNombre(), 45, 20, 0);
            reporte.contenido.roundRectangle(250, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 20, 0);
            reporte.contenido.roundRectangle(440, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RECIBE: " + almacen.getEntrego(), 440,
                    20, 0);
        }
        ///
        reporte.finTexto();
        reporte.contenido.setFontAndSize(bf, 12);
        //agregamos renglones vacios para dejar un espacio(tabla)
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor cabecera = BaseColor.GRAY;
        int centro = Element.ALIGN_CENTER;

        tabla.addCell(reporte.celda("N", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("#", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("N Parte", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Descripcin", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Med", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Cant", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    } 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  www  .ja v a 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;
        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.formatosPedido.java

private void cabeceraCompra(PDF reporte, BaseFont bf, PdfPTable tabla, Almacen almacen, Orden ord) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from w w w .  j a v a  2s . c o m
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));
        reporte.contenido.roundRectangle(35, 755, 280, 10, 0);
        reporte.contenido.roundRectangle(35, 735, 280, 20, 0);
        ////*2
        reporte.contenido.roundRectangle(35, 388, 280, 10, 0);
        reporte.contenido.roundRectangle(35, 368, 280, 20, 0);
        ////         
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 13);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.agregaObjeto(reporte.crearImagen("imagenes/grande300115.jpg", 335, -23, 30));
        /*2*/reporte.agregarImagen(reporte.crearImagen("imagenes/grande300115.jpg", 100, -390, 30));//-390//-375
        reporte.contenido.setFontAndSize(bf, 12);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        if (miAlmacen.getTipoMovimiento() == 1) {
            if (miAlmacen.getOperacion() == 1 || miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 3)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimiento en Almacn (Entrada de Material): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 767, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimientos de Almacn (Devolucin de ventas): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 767, 0);
            ////*2
            if (miAlmacen.getOperacion() == 1 || miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 3)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimiento en Almacn (Entrada de Material): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 400, 0);
            if (miAlmacen.getOperacion() == 6)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimientos de Almacn (Devolucin de ventas): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 400, 0);
            /////
        } else {
            if (miAlmacen.getOperacion() == 1 || miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 3)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimiento de Almacn (Devolucin de material a proveedor): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 767, 0);
            if (miAlmacen.getOperacion() == 6)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimientos de Almacn (Entrega de ventas): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 767, 0);
            ///**2
            if (miAlmacen.getOperacion() == 1 || miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 3)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimiento de Almacn (Devolucin de material a proveedor): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 400, 0);
            if (miAlmacen.getOperacion() == 6)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimientos de Almacn (Entrega de ventas): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 400, 0);
            ///
        }

        reporte.contenido.setFontAndSize(bf, 7);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 306, 757, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 306, 390, 0);
        if (ord != null)
            ord = (Orden) session.get(Orden.class, ord.getIdOrden());

        //************************datos de movimiento****************************
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Materiales y Refacciones del Almacn",
                40, 757, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "Materiales y Refacciones del Almacn", 40, 390, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "N. Movimiento: " + almacen.getIdAlmacen(), 40, 747, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "N. Movimiento: " + almacen.getIdAlmacen(), 40, 380, 0);
        if (almacen.getTipoMovimiento() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Entrada", 120,
                    747, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Salida", 120,
                    747, 0);
        ////2
        if (almacen.getTipoMovimiento() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Entrada", 120,
                    380, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Salida", 120,
                    380, 0);
        ////
        if (almacen.getOperacion() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido", 220,
                    747, 0);
        if (almacen.getOperacion() == 2)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido E.", 220,
                    747, 0);
        if (almacen.getOperacion() == 3)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido A.", 220,
                    747, 0);
        if (almacen.getOperacion() == 6)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Venta", 220, 747,
                    0);
        ////2
        if (almacen.getOperacion() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido", 220,
                    380, 0);
        if (almacen.getOperacion() == 2)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido E.", 220,
                    380, 0);
        if (almacen.getOperacion() == 3)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido A.", 220,
                    380, 0);
        if (almacen.getOperacion() == 6)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Venta", 220, 380,
                    0);
        ////
        if (ord != null) {
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N. Orden: " + ord.getIdOrden(), 40,
                    737, 0);
            /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N. Orden: " + ord.getIdOrden(),
                    40, 370, 0);
        }

        //Firmas de material 
        if (miAlmacen.getTipoMovimiento() == 1) {
            reporte.contenido.roundRectangle(45, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ENTREGA: " + almacen.getEntrego(), 45,
                    440, 0);
            reporte.contenido.roundRectangle(250, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 440, 0);
            reporte.contenido.roundRectangle(440, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "RECIBE: " + almacen.getUsuario().getEmpleado().getNombre(), 440, 440, 0);
        } else {
            reporte.contenido.roundRectangle(45, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "ENTREGA: " + almacen.getUsuario().getEmpleado().getNombre(), 45, 440, 0);
            reporte.contenido.roundRectangle(250, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 440, 0);
            reporte.contenido.roundRectangle(440, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RECIBE: " + almacen.getEntrego(), 440,
                    440, 0);
        }

        ///2
        if (miAlmacen.getTipoMovimiento() == 1) {
            reporte.contenido.roundRectangle(45, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ENTREGA: " + almacen.getEntrego(), 45,
                    20, 0);
            reporte.contenido.roundRectangle(250, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 20, 0);
            reporte.contenido.roundRectangle(440, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "RECIBE: " + almacen.getUsuario().getEmpleado().getNombre(), 440, 20, 0);
        } else {
            reporte.contenido.roundRectangle(45, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "ENTREGA: " + almacen.getUsuario().getEmpleado().getNombre(), 45, 20, 0);
            reporte.contenido.roundRectangle(250, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 20, 0);
            reporte.contenido.roundRectangle(440, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RECIBE: " + almacen.getEntrego(), 440,
                    20, 0);
        }
        ///

        reporte.finTexto();
        reporte.contenido.setFontAndSize(bf, 12);
        //agregamos renglones vacios para dejar un espacio(tabla)
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor cabecera = BaseColor.GRAY;
        int centro = Element.ALIGN_CENTER;

        tabla.addCell(reporte.celda("N", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("#", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("N Parte", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Descripcin", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Med", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Cant", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        if (tabla.getNumberOfColumns() > 6) {
            tabla.addCell(reporte.celda("Costo c/u", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("Total", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    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);//  w  w  w.  j a  v  a 2s.  c o  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  va2  s.c o  m*/
    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);/*from   www.  j  a v a  2 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.Reporte2.java

public void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo1, int op) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*w w w  . ja v  a2 s . c  om*/
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));

        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 14);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 35, 755, 0);
        reporte.contenido.setFontAndSize(bf, 8);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        String titulo = titulo1;
        if (op == 1) {
            if (t_fecha1.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " del " + t_fecha1.getText();
            if (t_fecha2.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " al " + t_fecha2.getText();
        }
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 745, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 570, 745, 0);

        reporte.finTexto();
        //agregamos renglones vacios para dejar un espacio
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

        BaseColor cabecera = BaseColor.GRAY;
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        if (op == 1) {
            for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
                tabla.addCell(reporte.celda(t_datos.getColumnName(a), font, cabecera, centro, 0, 1,
                        Rectangle.RECTANGLE));
            }
        }
        if (op == 2) {
            for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
                tabla.addCell(reporte.celda(t_datos1.getColumnName(a), font, cabecera, centro, 0, 1,
                        Rectangle.RECTANGLE));
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:Almacen.Reporte2.java

public void cabecera1(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo1, int op) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from  w ww . j a  v  a 2 s. co  m
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));

        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 14);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 35, 755, 0);
        reporte.contenido.setFontAndSize(bf, 8);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        String titulo = titulo1;

        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 745, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 570, 745, 0);

        reporte.finTexto();
        //agregamos renglones vacios para dejar un espacio
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

        BaseColor cabecera = BaseColor.GRAY;
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;

        for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
            tabla.addCell(reporte.celda(t_datos2.getColumnName(a), font, cabecera, centro, 0, 1,
                    Rectangle.RECTANGLE));
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}