Example usage for com.itextpdf.text.pdf AcroFields setField

List of usage examples for com.itextpdf.text.pdf AcroFields setField

Introduction

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

Prototype

public boolean setField(String name, String value) throws IOException, DocumentException 

Source Link

Document

Sets the field value.

Usage

From source file:Servicios.formatos.java

private void b_encuenta1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_encuenta1ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//w  w w  .j  a va2 s.c o  m

    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(orden));
        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        Date fecha = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);
        File folder = new File("reportes/" + ord.getIdOrden());
        folder.mkdirs();
        PdfReader reader = new PdfReader("imagenes/PlantillaEncueStaQualitas.pdf");
        PdfStamper stamp = new PdfStamper(reader,
                new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-encuesta.pdf"));
        PdfContentByte cb = stamp.getUnderContent(1);
        AcroFields fdfDoc = stamp.getAcroFields();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

        cb.beginText();
        //EMPRESA
        if (con.getEmpresa() != null)
            fdfDoc.setField("TALLER", con.getEmpresa());
        else
            fdfDoc.setField("TALLER", "");
        //ASEGURADO
        if (ord.getClientes().getNombre() != null)
            fdfDoc.setField("ASEGURADO", ord.getClientes().getNombre());
        else
            fdfDoc.setField("ASEGURADO", "");
        //REPORTE
        if (ord.getNoReporte() != null)
            fdfDoc.setField("REPORTE", ord.getNoReporte());
        else
            fdfDoc.setField("REPORTE", "");
        //VEHICULO
        String auto = "";
        if (ord.getTipo().getTipoNombre() != null)
            auto = ord.getTipo().getTipoNombre();

        if (ord.getMarca().getMarcaNombre() != null)
            auto += "/" + ord.getMarca().getMarcaNombre();
        fdfDoc.setField("VEHICULO", auto);
        //PLACAS
        if (ord.getNoPlacas() != null)
            fdfDoc.setField("PLACAS", ord.getNoPlacas());
        else
            fdfDoc.setField("PLACAS", "");
        //TELEFONO
        if (ord.getClientes().getTelefono() != null)
            fdfDoc.setField("TELEFONO", ord.getClientes().getTelefono());
        else
            fdfDoc.setField("TELEFONO", "");
        //EMAIL
        if (ord.getClientes().getEmail() != null)
            fdfDoc.setField("EMAIL", ord.getClientes().getEmail());
        else
            fdfDoc.setField("EMAIL", "");

        cb.endText();
        stamp.close();
        PDF reporte = new PDF();
        reporte.cerrar();
        reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-encuesta.pdf");

    } 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();
}

From source file:Servicios.formatos.java

private void b_salida1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_salida1ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/*from   w w  w.jav  a  2 s.com*/

    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(orden));
        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        Date fecha = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);
        File folder = new File("reportes/" + ord.getIdOrden());
        folder.mkdirs();
        PdfReader reader = new PdfReader("imagenes/PlantillaPromesaAxa.pdf");
        PdfStamper stamp = new PdfStamper(reader,
                new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-promesaAXA.pdf"));
        PdfContentByte cb = stamp.getUnderContent(1);
        AcroFields fdfDoc = stamp.getAcroFields();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

        cb.beginText();
        //IMAGEN
        try {
            Image img = Image.getInstance(ord.getCompania().getFoto());
            img.setAbsolutePosition(25, 695);
            img.scaleAbsoluteWidth(75);
            img.scaleAbsoluteHeight(45);
            cb.addImage(img, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //SINIESTRO
        if (ord.getSiniestro() != null)
            fdfDoc.setField("Siniestro", ord.getSiniestro());
        else
            fdfDoc.setField("Siniestro", "");
        //FECHA SINIESTRO
        if (ord.getFechaSiniestro() != null)
            fdfDoc.setField("FechaSiniestro", ord.getFechaSiniestro().toString());
        else
            fdfDoc.setField("FechaSiniestro", "");
        //NOMBRE DEL TALLER
        if (con.getEmpresa() != null)
            fdfDoc.setField("NombreTaller", con.getEmpresa());
        else
            fdfDoc.setField("NombreTaller", "");
        //DIRECCION DEL TALLER 
        String direccion = "";
        if (con.getDireccion() != null)
            direccion += con.getDireccion() + " ";
        if (con.getNo() != null)
            direccion += con.getNo() + " ";
        if (con.getColonia() != null)
            direccion += con.getColonia() + " ";
        fdfDoc.setField("DireccionTaller", direccion);
        //FECHA INGRESO
        if (ord.getFecha() != null)
            fdfDoc.setField("FechaIngreso", ord.getFecha().toString());
        else
            fdfDoc.setField("FechaIngreso", "");
        //FECHA PROMESA
        if (ord.getFechaCliente() != null)
            fdfDoc.setField("FechaPromesa", ord.getFechaCliente().toString());
        else
            fdfDoc.setField("FechaPromesa", "");

        cb.endText();
        stamp.close();
        PDF reporte = new PDF();
        reporte.cerrar();
        reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-promesaAXA.pdf");

    } 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();
}

From source file:Servicios.SmLogistics.java

private void b_desgaste_formatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_desgaste_formatoActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//from   w w w  .java2s. com
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        Orden ord = (Orden) session.get(Orden.class, orden_act.getIdOrden());

        Date fecha = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);
        File folder = new File("reportes/" + ord.getIdOrden());
        folder.mkdirs();
        PdfReader reader = new PdfReader("imagenes/Desgaste.pdf");
        PdfStamper stamp = new PdfStamper(reader,
                new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-DESGASTE.pdf"));
        PdfContentByte cb = stamp.getUnderContent(1);
        AcroFields fdfDoc = stamp.getAcroFields();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        Image img;
        cb.beginText();

        try {
            fdfDoc.setField("CLIENTE", ord.getClientes().getNombre());
        } catch (Exception e) {
            fdfDoc.setField("NOMBRE", "");
        }
        try {
            fdfDoc.setField("ORDEN", "" + ord.getIdOrden());
        } catch (Exception e) {
            fdfDoc.setField("ORDEN", "");
        }
        try {
            fdfDoc.setField("ECO", ord.getNoEconomico());
        } catch (Exception e) {
            fdfDoc.setField("ECO", "");
        }
        try {
            fdfDoc.setField("SERIE", ord.getNoMotor());
        } catch (Exception e) {
            fdfDoc.setField("SERIE", "");
        }
        try {
            fdfDoc.setField("VIN", ord.getNoSerie());
        } catch (Exception e) {
            fdfDoc.setField("VIN", "");
        }
        cb.endText();
        stamp.close();
        PDF reporte = new PDF();
        reporte.visualizar2("reportes/" + ord.getIdOrden() + "/" + valor + "-DESGASTE.pdf");
        reporte.cerrar();
    } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto");
    } finally {
        if (session != null)
            if (session.isOpen())
                session.close();
    }
}

From source file:Servicios.SmLogistics.java

private void b_pago_formatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_pago_formatoActionPerformed
    // TODO add your handling code here:
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*from  w ww.j  av  a  2 s.c  o  m*/
        Orden ord = (Orden) session.get(Orden.class, orden_act.getIdOrden());
        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        Date fecha = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);

        String formato = "PagoAXA.pdf";//ord.getCompania().getFormatoPago();
        File folder = new File("reportes/" + ord.getIdOrden());
        folder.mkdirs();

        PdfReader reader = new PdfReader("imagenes/" + formato);
        PdfStamper stamp = new PdfStamper(reader,
                new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-Pago.pdf"));
        PdfContentByte cb = stamp.getUnderContent(1);
        AcroFields fdfDoc = stamp.getAcroFields();

        cb.beginText();
        //IMAGEN
        try {
            Image img = Image.getInstance("imagenes/" + con.getLogo());
            img.setAbsolutePosition(25, 710);
            img.scaleAbsoluteWidth(75);
            img.scaleAbsoluteHeight(50);
            cb.addImage(img, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Image img_1 = Image.getInstance(ord.getCompania().getFoto());
            img_1.setAbsolutePosition(500, 735);
            img_1.scaleAbsoluteWidth(80);
            img_1.scaleAbsoluteHeight(50);
            cb.addImage(img_1, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Foto foto = (Foto) session.createCriteria(Foto.class)
                .add(Restrictions.eq("orden.idOrden", orden_act.getIdOrden())).addOrder(Order.desc("fecha"))
                .setMaxResults(1).uniqueResult();
        if (foto != null) {
            try {
                Image img_2 = Image
                        .getInstance("ordenes/" + ord.getIdOrden() + "/miniatura/" + foto.getDescripcion());
                img_2.setAbsolutePosition(480, 558);
                img_2.scaleAbsoluteWidth(90);
                img_2.scaleAbsoluteHeight(50);
                cb.addImage(img_2, true);
            } catch (Exception e) {
            }
        }

        //NOMBRE DEL TALLER
        if (con.getEmpresa() != null)
            fdfDoc.setField("NombreEmpresa", con.getEmpresa());

        //DIRECCION DEL TALLER 
        String direccion = "";
        if (con.getDireccion() != null)
            direccion += con.getDireccion() + " ";
        if (con.getNo() != null)
            direccion += con.getNo() + " ";
        if (con.getColonia() != null)
            direccion += con.getColonia();
        direccion = direccion.toUpperCase();
        fdfDoc.setField("DireccionEmpresa", direccion);

        //Municipio, Estado, CP
        String municipio = "";
        if (con.getMunicipio() != null)
            municipio += con.getMunicipio() + " ";
        if (con.getEstado() != null)
            municipio += con.getEstado() + " ";
        if (con.getCp() != null)
            municipio += con.getCp();
        municipio = municipio.toUpperCase();
        fdfDoc.setField("ColoniaEmpresa", municipio);

        //Pagina Web y Telefonos
        fdfDoc.setField("SitioEmpresa", "tracto.ddns.net");
        fdfDoc.setField("TelefonoEmpresa", "(722) 199 24 04 / 275 19 45");

        //Datos de la compaia
        fdfDoc.setField("Aseguradora1", ord.getCompania().getSocial());
        if (ord.getCompania().getDireccion() != null)
            fdfDoc.setField("Aseguradora2", ord.getCompania().getDireccion());
        if (ord.getCompania().getColonia() != null)
            fdfDoc.setField("Aseguradora3", ord.getCompania().getColonia());
        /*if(ord.getCompania().getComentarios()!=null)
            fdfDoc.setField("Extra", ord.getCompania().getComentarios());*/

        //Orden de trabajo
        fdfDoc.setField("Orden", "" + ord.getIdOrden());

        //FECHA INGRESO
        if (ord.getFecha() != null)
            fdfDoc.setField("FechaRecepcion", ord.getFecha().toString());

        //Marca
        fdfDoc.setField("Marca", ord.getMarca().getMarcaNombre());

        //Tipo
        fdfDoc.setField("Modelo", "" + ord.getTipo().getTipoNombre());

        //Placas
        if (ord.getNoPlacas() != null)
            fdfDoc.setField("Placas", "" + ord.getNoPlacas());

        //Poliza
        if (ord.getPoliza() != null)
            fdfDoc.setField("Poliza", "" + ord.getPoliza());

        //Siniestro
        if (ord.getSiniestro() != null)
            fdfDoc.setField("Siniestro", "" + ord.getSiniestro());

        //Datos cliente
        if (ord.getClientes() != null) {
            fdfDoc.setField("Nombre", ord.getClientes().getNombre());
            if (ord.getClientes().getContacto() != null)
                fdfDoc.setField("Contacto", ord.getClientes().getContacto());
        }

        //Datos de atencion a clientes
        fdfDoc.setField("Tel1", "722 299 240 25");
        fdfDoc.setField("Id1", "52*167862*13");
        fdfDoc.setField("Email1", "atencionaclientes@tractoservicio.com");
        fdfDoc.setField("Wat1", "722 299 240 25");

        float tam[] = new float[] { 160, 80, 130, 170 };
        Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
        PDF reporte = new PDF();
        PdfPTable tabla = reporte.crearTabla(4, 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;

        if (formato.compareToIgnoreCase("PagoAXA.pdf") != 0) {
            tabla.addCell(reporte.celda("BANCO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("NO CONVENIO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("N DE CUENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(
                    reporte.celda("NOMBRE DE LA COMPAIA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));

            Cuenta[] cuentas = (Cuenta[]) ord.getCompania().getCuentas().toArray(new Cuenta[0]);
            if (cuentas.length > 0) {
                for (int i = 0; i < cuentas.length; i++) {
                    tabla.addCell(reporte.celda(cuentas[i].getBanco(), font, contenido, izquierda, 0, 1,
                            Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(cuentas[i].getConvenio().toString(), font, contenido, izquierda,
                            0, 1, Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(cuentas[i].getTransferencia(), font, contenido, izquierda, 0, 1,
                            Rectangle.RECTANGLE));
                    tabla.addCell(reporte.celda(cuentas[i].getNombre(), font, contenido, izquierda, 0, 1,
                            Rectangle.RECTANGLE));
                }
            }

            tabla.completeRow();
            tabla.writeSelectedRows(0, -1, 40, 420, cb);
        }
        DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
        formatoPorcentaje.setMinimumFractionDigits(2);

        cb.setTextMatrix(160, 466);
        BaseFont bf = BaseFont.createFont();
        cb.setFontAndSize(bf, 9);
        cb.showText("" + formatoPorcentaje.format(orden_act.getDeducible()));

        cb.setTextMatrix(450, 466);
        cb.showText("" + formatoPorcentaje.format(orden_act.getDemerito()));
        cb.endText();

        stamp.close();
        reporte.cerrar();
        reporte.visualizar2("reportes/" + ord.getIdOrden() + "/" + valor + "-Pago.pdf");

    } catch (Exception 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();
}