mail.java Source code

Java tutorial

Introduction

Here is the source code for mail.java

Source

import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Rectangle;
import java.awt.Toolkit;
import static java.awt.event.KeyEvent.VK_ENTER;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.util.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.regex.Pattern;

import javax.swing.JOptionPane;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */ /**
     *
     * @author daniel
     */

public class mail extends javax.swing.JFrame {

    private conector Conector;
    String idmatricula = "";
    double total = 0.0;
    //    private final reg1 menu;
    ArrayList<Items> itemsList = new ArrayList<Items>();
    ArrayList<Bonos> ListaBono = new ArrayList<Bonos>();
    String nombre = "";
    String apellido = "";
    int documento;
    String direccion = "";
    String email = "";

    /**
     * Creates new form mail
     */
    public mail(conector Conector) {
        initComponents();
        this.Conector = Conector;
        String titulo = "Consejo Profesional de Abogacia";
        String estado = "Estado de cuenta de Matricula";
        Object columnas[] = { "Perido", "Deuda", "Vto-Periodo", "Abonado", "Fecha de Pago", "Saldo" };
        setIcon();
        //        menu = new reg1();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        matricula = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        Detalledeuda = new javax.swing.JTable();
        jScrollPane1 = new javax.swing.JScrollPane();
        Area = new javax.swing.JTextArea();
        Imprimir = new javax.swing.JButton();
        EnviarMail = new javax.swing.JButton();
        TTotal = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }

            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }

            public void windowDeactivated(java.awt.event.WindowEvent evt) {
                formWindowDeactivated(evt);
            }
        });

        jLabel1.setText("Matricula:");

        matricula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                matriculaKeyReleased(evt);
            }
        });

        Detalledeuda.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Periodo", "Vencimiento", "Importe" }) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.Double.class };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }
        });
        Detalledeuda.setColumnSelectionAllowed(true);
        jScrollPane2.setViewportView(Detalledeuda);
        Detalledeuda.getColumnModel().getSelectionModel()
                .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        Area.setColumns(20);
        Area.setRows(5);
        jScrollPane1.setViewportView(Area);

        Imprimir.setText("Guardar Impresin");
        Imprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ImprimirActionPerformed(evt);
            }
        });

        EnviarMail.setText("Enviar Mail");
        EnviarMail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EnviarMailActionPerformed(evt);
            }
        });

        TTotal.setEditable(false);

        jLabel2.setText("Total:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(14, 14, 14).addComponent(jLabel1).addGap(18, 18, 18)
                        .addComponent(matricula, javax.swing.GroupLayout.PREFERRED_SIZE, 96,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 423,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(EnviarMail, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(Imprimir, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap(31, Short.MAX_VALUE))
                .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2).addGap(72, 72, 72).addComponent(TTotal,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(layout.createSequentialGroup().addGap(46, 46, 46).addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel1).addComponent(matricula,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(Imprimir).addGap(44, 44, 44).addComponent(EnviarMail)))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 163,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(TTotal, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel2))
                        .addContainerGap(28, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botones(boolean valor) {
        Imprimir.setEnabled(valor);

    }

    private void matriculaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_matriculaKeyReleased
        // TODO add your handling code here:
        if (evt.getKeyCode() == VK_ENTER) {
            itemsList.clear();
            total = 0;
            try {
                DefaultTableModel modelo = (DefaultTableModel) Detalledeuda.getModel();
                modelo.setRowCount(0);

                Connection conn;
                conn = Conector.Connect();
                System.out.println("serealizo con exito");

                System.out.println(Conector.getBase());
                System.out.println("no fue:");

                PreparedStatement resultado;
                PreparedStatement deuda;
                //                 Items item = new Items();

                if (conn == null) {
                    System.out.println("coneccion no se realizo");
                } else {
                    String sql = "SELECT * FROM abogados a left join matriculas m on a.`ID_ABOGADO`=m.id_abogado where m.id_matricula=?";
                    resultado = conn.prepareStatement(sql);
                    resultado.setString(1, matricula.getText());
                    ResultSet rs = resultado.executeQuery();
                    Area.setEditable(false);
                    if (rs.first()) {
                        System.out.println(rs.getRow());
                        rs.beforeFirst();//regresa el puntero al primer registro
                        while (rs.next()) {

                            nombre = rs.getString("NOMBRES");
                            apellido = rs.getString("APELLIDO");
                            documento = rs.getInt("DOCUMENTO");
                            direccion = rs.getString("DIRESTUDIO");
                            email = rs.getString("email");
                            System.out.format("%s,%s,%s,%s,%s\n", documento, nombre, apellido, direccion, email);
                            Area.setText("Nombre:" + nombre + "," + apellido + "\n Direccin" + direccion
                                    + "\n Mail:" + email);
                            idmatricula = rs.getString("id_matricula");
                            itemsList.add(new Items(documento, nombre, apellido, direccion, email));
                        }

                    } else {
                        System.out.println("no existe ");
                        modelo.setRowCount(0);
                        idmatricula = "0";
                        TTotal.setText("");
                        nombre = "";
                        apellido = "";
                        documento = 0;
                        direccion = "";
                        email = "";
                        Area.setText("");
                    }

                    rs.close();
                    resultado.close();
                    //                
                    if (idmatricula != "0") {

                        String sql1 = "select * from cuenta_matricula where id_matricula=? and fecha_pago is null";
                        deuda = conn.prepareStatement(sql1);
                        SimpleDateFormat formatoDeFecha = new SimpleDateFormat("yyyy");
                        SimpleDateFormat fechaperiodo = new SimpleDateFormat("dd-MM-yyyy");
                        deuda.setString(1, idmatricula);
                        ResultSet ds = deuda.executeQuery();
                        DecimalFormatSymbols simbolos = new DecimalFormatSymbols();
                        simbolos.setDecimalSeparator('.');
                        DecimalFormat decim = new DecimalFormat("0.00", simbolos);
                        if (ds.first()) {

                            ds.beforeFirst();//regresa el puntero al primer registro
                            while (ds.next()) {
                                String periodo = ds.getString("vencim_cuota");
                                String vencimiento = ds.getString("vencim_cuota");
                                double importe = ds.getDouble("monto_cuota");

                                Double importe1 = Double.valueOf(decim.format(importe));
                                try {
                                    Date per = formatoDeFecha.parse(periodo);
                                    periodo = formatoDeFecha.format(per);

                                    Date vencimi = fechaperiodo.parse(vencimiento);
                                    vencimiento = fechaperiodo.format(vencimi);
                                    System.out.format("%s,%s,%s\n", periodo, vencimiento, importe1);
                                    modelo.addRow(new Object[] { periodo, vencimiento, importe1 });
                                    itemsList.add(new Items(periodo, vencimiento, importe1));
                                    total = importe + total;
                                } catch (ParseException ex) {
                                    ex.printStackTrace();
                                }
                                botones(true);

                            }

                            ds.close();
                            TTotal.setText(String.valueOf(decim.format(total)));
                        }
                    } else {
                        modelo.setRowCount(0);
                        botones(false);

                    }

                    //                Object[] data= {"dedos","registro","compra"};
                    //                modelo.addRow(data);
                }
            } catch (SQLException ex) {
                Logger.getLogger(mail.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }//GEN-LAST:event_matriculaKeyReleased

    private void ImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ImprimirActionPerformed
        try {
            // TODO add your handling code here:

            PDDocument documento = new PDDocument();
            PDPage paginablanco = new PDPage();
            documento.addPage(paginablanco);
            PDPageContentStream content;
            try {
                content = new PDPageContentStream(documento, paginablanco);

                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 9);
                content.newLineAtOffset(50, 780);
                content.showText("Consejo Profesional de Abogacia");
                content.endText();
                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 9);
                content.newLineAtOffset(450, 780);
                Locale espanol = new Locale("es", "ES");
                SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE MMMM d HH:mm:ss z yyyy", espanol);
                String fecha = dateFormat.format(new Date());
                content.showText(fecha);
                content.endText();
                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 6);
                content.newLineAtOffset(50, 770);
                content.showText("Direccin: San Martin 457 - Formosa");
                content.endText();
                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 10);
                content.newLineAtOffset(200, 750);
                content.showText("Estado de Cuenta de Matricula");
                content.endText();
                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 10);
                content.newLineAtOffset(50, 735);
                content.showText("Matricula N " + idmatricula + "       Nombre:     " + nombre + "," + apellido);//
                content.endText();
                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 10);
                content.newLineAtOffset(100, 705);
                content.showText(
                        "Items       Periodo                        Vencimiento                            Importe");
                content.endText();
                content.addRect(50, 10, 400, 700);

                int j = 0;
                int renglon = 685;

                System.out.println(itemsList.size());

                for (int i = 1; i < itemsList.size(); i++) {

                    content.beginText();
                    content.setFont(PDType1Font.HELVETICA, 10);
                    j++;
                    content.newLineAtOffset(100, renglon);
                    content.showText("  " + i + "              " + itemsList.get(i).getVencimiento()
                            + "                                " + itemsList.get(i).getPeriodo()
                            + "                                      "
                            + String.valueOf(itemsList.get(i).getImporte()));
                    renglon = renglon - 13;
                    content.endText();
                }
                content.beginText();
                content.newLineAtOffset(100, renglon - 20);
                DecimalFormatSymbols simbolos = new DecimalFormatSymbols();
                simbolos.setDecimalSeparator('.');
                DecimalFormat decim = new DecimalFormat("0.00", simbolos);

                content.showText("Total Adeudado            :$ " + String.valueOf(decim.format(total)));
                content.endText();
                content.close();

                documento.save("matricula_" + idmatricula + ".pdf");
                documento.close();
                System.out.println("guardo archivo matricula_" + idmatricula + ".pdf");
                EnviarMail.setEnabled(true);

            } catch (IOException ex) {
                EnviarMail.setEnabled(false);
                Logger.getLogger(mail.class.getName()).log(Level.SEVERE, null, ex);
            }
            bonos();

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

    }//GEN-LAST:event_ImprimirActionPerformed

    private void EnviarMailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EnviarMailActionPerformed
        // TODO add your handling code here:
        if ((email == null) || (email.isEmpty())) {
            int resp = JOptionPane.showConfirmDialog(null,
                    "Atencin Falta el correo, No podra enviar, Agregue el Correo", "Atencin",
                    JOptionPane.DEFAULT_OPTION);
        } else {
            int resp = JOptionPane.showConfirmDialog(null,
                    "envia el correo a " + nombre + "," + apellido + " Matricula: " + idmatricula,
                    "Correo electronico", JOptionPane.OK_CANCEL_OPTION);
            if (JOptionPane.OK_OPTION == resp) {
                System.out.println("Selecciona opcin Afirmativa" + resp);
                List<String> adjuntos = new ArrayList<String>();

                Enviomail de = new Enviomail();
                File fm = new File("matricula_" + idmatricula + ".pdf");
                if (fm.exists()) {
                    adjuntos.add("matricula_" + idmatricula + ".pdf");
                }
                File fb = new File("matricula_" + idmatricula + "_bonos.pdf");
                if (fb.exists()) {
                    adjuntos.add("matricula_" + idmatricula + "_bonos.pdf");
                }

                Properties configuracionmail = new Properties();
                configuracionmail.put("texto", "Estimado Sr/a:" + apellido + " , " + nombre
                        + ".</br> Adjunto el saldo adeudado hasta la fecha.</br> Sin mas quedo a su dispocin</br> ");
                configuracionmail.put("To", email);
                try {
                    de.Enviomail(adjuntos, configuracionmail);
                } catch (IOException ex) {
                    Logger.getLogger(reg1.class.getName()).log(Level.SEVERE, null, ex);
                }

            } else {
                System.out.println("No selecciona una opcin afirmativa" + resp);
            }
            if (resp == 0) {
                System.out.print(itemsList.get(1).getPeriodo() + "-" + itemsList.get(1).getImporte());

            }
        }
    }//GEN-LAST:event_EnviarMailActionPerformed

    private void formWindowDeactivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeactivated
        // TODO add your handling code here:
        //        menu.bandera=false;
    }//GEN-LAST:event_formWindowDeactivated

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
        Imprimir.setEnabled(false);
        TTotal.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        EnviarMail.setEnabled(false);
    }//GEN-LAST:event_formWindowActivated

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(mail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(mail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(mail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(mail.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

            }
        });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea Area;
    private javax.swing.JTable Detalledeuda;
    private javax.swing.JButton EnviarMail;
    private javax.swing.JButton Imprimir;
    private javax.swing.JTextField TTotal;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField matricula;
    // End of variables declaration//GEN-END:variables

    private void setIcon() {
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("users6.png")));
    }
    //public static String remove2(String input) {
    //    // Descomposicin cannica
    //    String normalized = Normalizer.normalize(input, Normalizer.Form.NFD);
    //    // Nos quedamos nicamente con los caracteres ASCII
    //    Pattern pattern = Pattern.compile("\\000a");
    //    return pattern.matcher(normalized).replaceAll("");
    //}//remove2

    private void bonos() throws SQLException {
        //**
        double total = 0;
        ListaBono.clear();
        if (idmatricula != "0") {
            Connection conn;
            try {
                conn = Conector.Connect();

                System.out.println("Bonos");

                PreparedStatement resultado;
                PreparedStatement bono;
                String sql1 = "select * from bonos b left join juzgados j on b.ID_JUZGADO=j.id_juzgado where ID_MATRICULA=? ORDER BY ANO  ";
                bono = conn.prepareStatement(sql1);

                bono.setString(1, idmatricula);
                ResultSet ds = bono.executeQuery();
                DecimalFormatSymbols simbolos = new DecimalFormatSymbols();
                SimpleDateFormat formatofecha = new SimpleDateFormat("dd-MM-yyyy");
                simbolos.setDecimalSeparator('.');
                DecimalFormat decim = new DecimalFormat("0.00", simbolos);
                if (ds.first()) {

                    ds.beforeFirst();//regresa el puntero al primer registro
                    while (ds.next()) {
                        int numero_expediente = ds.getInt("NUMERO_EXPTE");
                        String ano = ds.getString("ANO");
                        String caratula = ds.getString("cara");
                        String fecha_actuacion = ds.getString("FECHA_ACTUACION");
                        String juzgado = ds.getString("descripcion");
                        double importe = ds.getDouble("MONTOBONO");

                        Double monto_bono = Double.valueOf(decim.format(importe));
                        caratula = caratula.replaceAll("\r\n", " ");
                        caratula = caratula.replaceAll("\n", " ");
                        caratula = caratula.replaceAll("\\\\\\\\", "");

                        //                                    Date per =formatofecha.parse(fecha_pa);
                        //                                   String fecha_pago = formatofecha.format(per);
                        System.out.println(idmatricula);
                        System.out.format("%s,%s,%s,%s,%s,%s\n", numero_expediente, ano, caratula.toLowerCase(),
                                juzgado.toLowerCase(), fecha_actuacion, importe);

                        ListaBono.add(
                                new Bonos(numero_expediente, ano, caratula, juzgado, fecha_actuacion, monto_bono));
                        total = total + monto_bono;

                        botones(true);

                    }

                    ds.close();
                    System.out.println(total);
                    System.out.println(ListaBono.size());
                }
            } catch (SQLException ex) {
                Logger.getLogger(mail.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        //**
        int alto = 595;
        int ancho = 842;
        PDDocument documento = new PDDocument();
        PDPage paginablanco = new PDPage(new PDRectangle(ancho, alto));

        documento.addPage(paginablanco);
        PDPageContentStream content;
        System.out.println(paginablanco.getMediaBox().getHeight() + "--" + paginablanco.getMediaBox().getWidth());

        try {
            content = new PDPageContentStream(documento, paginablanco);

            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 9);
            content.newLineAtOffset(50, alto - 20);
            content.showText("Consejo Profesional de Abogacia");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 9);
            content.newLineAtOffset(450, alto - 20);
            Locale espanol = new Locale("es", "ES");
            SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE MMMM d HH:mm:ss z yyyy", espanol);
            String fecha = dateFormat.format(new Date());
            content.showText(fecha);
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 6);
            content.newLineAtOffset(50, alto - 28);
            content.showText("Direccin: San Martin 457 - Formosa");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 10);
            content.newLineAtOffset(200, alto - 38);
            content.showText("BONOS DE ACCCIN LETRADA");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 8);
            content.newLineAtOffset(200, alto - 45);
            content.showText("Estado de Gestin de bonos del Profesional");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 9);
            content.newLineAtOffset(50, alto - 60);
            // para que no tenga errores las tabla de mysql cotejamiento en utf8_bin al cargar en la PDF da error si esta con el tema de las 
            content.showText("Matricula N: " + idmatricula + "       Nombre:     " + nombre + "," + apellido);//
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 8);
            content.newLineAtOffset(50, alto - 75);
            content.showText("Item");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 8);
            content.newLineAtOffset(70, alto - 75);
            content.showText("Expte");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 8);
            content.newLineAtOffset(100, alto - 75);
            content.showText("Ao");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 8);
            content.newLineAtOffset(130, alto - 75);
            content.showText("Caratula");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 8);
            content.newLineAtOffset(500, alto - 75);
            content.showText("Juzgado");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 8);
            content.newLineAtOffset(650, alto - 75);
            content.showText("Monto");
            content.endText();
            content.beginText();
            content.setFont(PDType1Font.HELVETICA, 8);
            content.newLineAtOffset(680, alto - 75);
            content.showText("Vencimiento");
            content.endText();
            content.setNonStrokingColor(Color.DARK_GRAY);
            content.addRect(25, 45, 700, 400);
            //            content.fill();
            int j = 0;
            int renglon = alto - 100;

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

                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 8);
                j++;
                content.newLineAtOffset(50, renglon);
                content.showText(String.valueOf(i + 1));
                content.endText();
                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 8);
                content.newLineAtOffset(70, renglon);
                content.showText(String.valueOf(ListaBono.get(i).getNumero_expediente()));
                content.endText();

                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 8);
                content.newLineAtOffset(100, renglon);
                content.showText(ListaBono.get(i).getAno());
                content.endText();

                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 8);
                content.newLineAtOffset(130, renglon);
                content.showText(String.valueOf(ListaBono.get(i).getCaratula()));
                content.endText();
                content.setFont(PDType1Font.COURIER, 8);

                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 8);
                content.newLineAtOffset(500, renglon);
                content.showText(ListaBono.get(i).getJuzgado());
                content.endText();

                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 8);
                content.newLineAtOffset(650, renglon);
                content.showText(String.valueOf(ListaBono.get(i).getMonto_bono()));
                content.endText();

                content.beginText();
                content.setFont(PDType1Font.HELVETICA, 8);
                content.newLineAtOffset(680, renglon);
                content.showText(ListaBono.get(i).getFecha_pago());
                content.endText();

                renglon = renglon - 13;
            }

            content.beginText();
            content.newLineAtOffset(100, renglon - 20);
            DecimalFormatSymbols simbolos = new DecimalFormatSymbols();
            simbolos.setDecimalSeparator('.');
            DecimalFormat decim = new DecimalFormat("0.00", simbolos);

            content.showText("Total Bonos Adeudados           :$ " + String.valueOf(decim.format(total)));
            content.endText();
            content.close();

            documento.save("matricula_" + idmatricula + "_bonos.pdf");
            documento.close();
            System.out.println("guardo archivo matricula_" + idmatricula + "_bonos.pdf");
            //            System.out.println(String.valueOf(decim.format(total)));

            EnviarMail.setEnabled(true);

        } catch (IOException ex) {
            EnviarMail.setEnabled(false);
            Logger.getLogger(mail.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}