Example usage for com.itextpdf.text Image scaleToFit

List of usage examples for com.itextpdf.text Image scaleToFit

Introduction

In this page you can find the example usage for com.itextpdf.text Image scaleToFit.

Prototype

public void scaleToFit(final float fitWidth, final float fitHeight) 

Source Link

Document

Scales the image so that it fits a certain width and height.

Usage

From source file:ServletsReportesPDF.ReporteCortaMaleza.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   w  w w. j  a va 2s.c  o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            Statement st3 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            st3 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from manejo_residuos_cosecha where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery("SELECT * from manejo_residuos_cosecha where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(120, 120);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE MANEJO RESIDUOS DE COSECHA", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(5);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Tipo de Manejo",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad Hectreas",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor de Hectreas",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);
                    tabla.addCell(celda5);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_mrc"));
                        tabla.addCell(rs2.getString("tipo_manejo_mrc"));
                        tabla.addCell(rs2.getString("cantidad_hectareas_mrc"));
                        tabla.addCell(rs2.getString("valor_hectareas_mrc"));
                        tabla.addCell(rs2.getString("valor_total_mrc"));

                    }
                    documento.add(tabla);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteDespalille.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w w .j  ava 2  s.  co m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from despalille where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(120, 120);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE DESPALILLE", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(4);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad Jornales",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Unitario Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Total Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_dsp"));
                        tabla.addCell(rs2.getString("cantidad_mano_obra_dsp"));
                        tabla.addCell(rs2.getString("precio_mano_obra_dsp"));
                        tabla.addCell(rs2.getString("total_mano_obra_dsp"));

                    }
                    documento.add(tabla);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteEntresaque.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   ww w. j  a  va2s.c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from entresaque where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE ENTRESAQUE", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(4);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad Jornales",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Unitario Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Total Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_etsq"));
                        tabla.addCell(rs2.getString("cantidad_mano_obra_etsq"));
                        tabla.addCell(rs2.getString("precio_mano_obra_etsq"));
                        tabla.addCell(rs2.getString("total_mano_obra_etsq"));

                    }
                    documento.add(tabla);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteFumigas.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from www  . j av a  2  s  . c  om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            Statement st3 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            st3 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from fumiga where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery(
                    "SELECT * from fumiga f JOIN  insumos_fumiga i on i.id_fumiga = f.id_fumiga where f.num_lote ='"
                            + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE FUMIGAS", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(6);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Tipo de Fumiga",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad Jornales",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Total Mano Obra",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda6 = new PdfPCell(new Paragraph("Valor Total Fumiga",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);
                    tabla.addCell(celda5);
                    tabla.addCell(celda6);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_fumiga"));
                        tabla.addCell(rs2.getString("nombre_fumiga_fumiga"));
                        tabla.addCell(rs2.getString("cantidad_mano_obra_fumiga"));
                        tabla.addCell(rs2.getString("valor_uni_mano_obra_fumiga"));
                        tabla.addCell(rs2.getString("valor_total_mano_obra_fumiga"));
                        tabla.addCell(rs2.getString("valor_total_fumiga"));

                    }
                    documento.add(tabla);

                    Paragraph par4 = new Paragraph();

                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    Font fontFooter2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par4.add(new Phrase("REPORTE INSUMOS FUMIGAS", fontFooter2));
                    par4.setAlignment(Element.ALIGN_CENTER);
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par4);

                    PdfPTable tabla2 = new PdfPTable(6);
                    FontFactory.registerDirectories();
                    PdfPCell celda10 = new PdfPCell(new Paragraph("Tipo",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda10.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda20 = new PdfPCell(new Paragraph("Nombre",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda20.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda30 = new PdfPCell(new Paragraph("Cantidad",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda30.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda40 = new PdfPCell(new Paragraph("Unidad",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda40.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda50 = new PdfPCell(new Paragraph("Valor Unitario",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda50.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda60 = new PdfPCell(new Paragraph("Valor Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda60.setHorizontalAlignment(Element.ALIGN_CENTER);

                    tabla2.addCell(celda10);
                    tabla2.addCell(celda20);
                    tabla2.addCell(celda30);
                    tabla2.addCell(celda40);
                    tabla2.addCell(celda50);
                    tabla2.addCell(celda60);

                    while (rs3.next()) {
                        tabla2.addCell(rs3.getString("tipo_insumo"));
                        tabla2.addCell(rs3.getString("nombre_insumo"));
                        tabla2.addCell(rs3.getString("cantidad_insumo"));
                        tabla2.addCell(rs3.getString("unidad_insumo"));
                        tabla2.addCell(rs3.getString("valor_unitario_insumo"));
                        tabla2.addCell(rs3.getString("valor_total_insumos"));
                    }

                    documento.add(tabla2);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteLiquidacion.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  www  . j av  a2s  .  c  om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from liquidacion where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE LIQUIDACIN", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(14);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Nmero de Tiquete",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Peso Neto",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Peso Final",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda5 = new PdfPCell(new Paragraph("F(24)",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda6 = new PdfPCell(new Paragraph("F(4)",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda7 = new PdfPCell(new Paragraph("Valor Unitario",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda8 = new PdfPCell(new Paragraph("Cantidad Bultos",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda9 = new PdfPCell(new Paragraph("Kilos Verdes",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda10 = new PdfPCell(new Paragraph("Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda11 = new PdfPCell(new Paragraph("Peso Final",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda12 = new PdfPCell(new Paragraph("Total Kilos Verdes",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda13 = new PdfPCell(new Paragraph("Total Valor Unitario",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda14 = new PdfPCell(new Paragraph("Valor Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);
                    tabla.addCell(celda5);
                    tabla.addCell(celda6);
                    tabla.addCell(celda7);
                    tabla.addCell(celda8);
                    tabla.addCell(celda9);
                    tabla.addCell(celda10);
                    tabla.addCell(celda11);
                    tabla.addCell(celda12);
                    tabla.addCell(celda13);
                    tabla.addCell(celda14);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_liquidacion"));
                        tabla.addCell(rs2.getString("n_tiquete_liquidacion"));
                        tabla.addCell(rs2.getString("peso_neto_liquidacion"));
                        tabla.addCell(rs2.getString("peso_final_liquidacion"));
                        tabla.addCell(rs2.getString("f_24_liquidacion"));
                        tabla.addCell(rs2.getString("f_4_liquidacion"));
                        tabla.addCell(rs2.getString("valor_unitario_liquidacion"));
                        tabla.addCell(rs2.getString("bultos_liquidacion"));
                        tabla.addCell(rs2.getString("kls_verdes_liquidacion"));
                        tabla.addCell(rs2.getString("valor_total_liquidacion"));
                        tabla.addCell(rs2.getString("total_liquidacion"));
                        tabla.addCell(rs2.getString("total_peso_final"));
                        tabla.addCell(rs2.getString("total_kilos_verdes"));
                        tabla.addCell(rs2.getString("total_valor_unitario"));

                    }
                    documento.add(tabla);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteMacheteada.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w w.  j  ava 2  s.  c  om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from macheteada where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE MACHETEADA", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(4);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad Jornales",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Unitario Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Total Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_mchd"));
                        tabla.addCell(rs2.getString("cantidad_mano_obra_mchd"));
                        tabla.addCell(rs2.getString("precio_mano_obra_mchd"));
                        tabla.addCell(rs2.getString("total_mano_obra_mchd"));

                    }
                    documento.add(tabla);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteMantenimiento.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w w  w  .  ja va  2  s  .c o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            Statement st3 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            st3 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from mantenimiento_lote where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery(
                    "SELECT * from mantenimiento_lote m JOIN  insumos_mantenimiento_lote i on i.id_mntlote = m.id_mntlote where m.num_lote ='"
                            + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE MANTENIMIENTO", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    Paragraph par2 = new Paragraph();
                    Font fonttitulo2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par2.add(new Phrase(Chunk.NEWLINE));
                    par2.add(new Phrase(Chunk.NEWLINE));
                    par2.add(new Phrase(Chunk.NEWLINE));
                    par2.add(new Phrase("REPORTE MANO DE OBRA", fonttitulo2));
                    par2.setAlignment(Element.ALIGN_CENTER);
                    par2.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par2);

                    PdfPTable tabla = new PdfPTable(6);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Costo Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Total Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda6 = new PdfPCell(new Paragraph("Costo Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);
                    tabla.addCell(celda5);
                    tabla.addCell(celda6);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_mntlote"));
                        tabla.addCell(rs2.getString("tipo_limpieza_mntlote"));
                        tabla.addCell(rs2.getString("cantidad_jornal_mntlote"));
                        tabla.addCell(rs2.getString("valor_jornal_mntlote"));
                        tabla.addCell(rs2.getString("valor_total_jornal_mntlote"));
                        tabla.addCell(rs2.getString("valor_total_mntlote"));

                    }
                    documento.add(tabla);

                    Paragraph par4 = new Paragraph();

                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    Font fontFooter2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par4.add(new Phrase("REPORTE INSUMOS MANTENIMIENTO", fontFooter2));
                    par4.setAlignment(Element.ALIGN_CENTER);
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par4);

                    PdfPTable tabla2 = new PdfPTable(6);
                    FontFactory.registerDirectories();
                    PdfPCell celda10 = new PdfPCell(new Paragraph("Tipo",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda10.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda20 = new PdfPCell(new Paragraph("Nombre",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda20.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda30 = new PdfPCell(new Paragraph("Cantidad",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda30.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda40 = new PdfPCell(new Paragraph("Unidad",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda40.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda50 = new PdfPCell(new Paragraph("Valor Unitario",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda50.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda60 = new PdfPCell(new Paragraph("Valor Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda60.setHorizontalAlignment(Element.ALIGN_CENTER);

                    tabla2.addCell(celda10);
                    tabla2.addCell(celda20);
                    tabla2.addCell(celda30);
                    tabla2.addCell(celda40);
                    tabla2.addCell(celda50);
                    tabla2.addCell(celda60);

                    while (rs3.next()) {
                        tabla2.addCell(rs3.getString("tipo_insumo"));
                        tabla2.addCell(rs3.getString("nombre_insumo"));
                        tabla2.addCell(rs3.getString("cantidad_insumo"));
                        tabla2.addCell(rs3.getString("unidad_insumo"));
                        tabla2.addCell(rs3.getString("valor_unitario_insumo"));
                        tabla2.addCell(rs3.getString("valor_total_insumos"));
                    }

                    documento.add(tabla2);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReportePajareoCeladuria.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w w w .j a v  a2  s  .  c  om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            Statement st3 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            st3 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from pajareo_celaduria_patos where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery("SELECT * from pajareo_celaduria_patos where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE PAJAREO Y CELADUR?A DE PATOS", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(4);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad Jornales",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Jornal",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Total Jornales",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_pcp"));
                        tabla.addCell(rs2.getString("cantidad_mano_obra_pcp"));
                        tabla.addCell(rs2.getString("valor_mano_obra_pcp"));
                        tabla.addCell(rs2.getString("valor_total_mano_obra_pcp"));

                    }
                    documento.add(tabla);

                    Paragraph par4 = new Paragraph();

                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    Font fontFooter2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par4.add(new Phrase("REPORTE INSUMOS PAJAREO Y CELADUR?A DE PATOS", fontFooter2));
                    par4.setAlignment(Element.ALIGN_CENTER);
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par4);

                    PdfPTable tabla2 = new PdfPTable(4);
                    FontFactory.registerDirectories();
                    PdfPCell celda10 = new PdfPCell(new Paragraph("Cantidad Plvora",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda10.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda20 = new PdfPCell(new Paragraph("Valor Plvora",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda20.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda30 = new PdfPCell(new Paragraph("Valor Total Plvora",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda30.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda40 = new PdfPCell(new Paragraph("Costo Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda40.setHorizontalAlignment(Element.ALIGN_CENTER);

                    tabla2.addCell(celda10);
                    tabla2.addCell(celda20);
                    tabla2.addCell(celda30);
                    tabla2.addCell(celda40);

                    while (rs3.next()) {
                        tabla2.addCell(rs3.getString("cantidad_polvora_pcp"));
                        tabla2.addCell(rs3.getString("valor_polvora_pcp"));
                        tabla2.addCell(rs3.getString("valor_total_polvora_pcp"));
                        tabla2.addCell(rs3.getString("valor_total_pcp"));
                    }

                    documento.add(tabla2);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReportePreparacionSuelo.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*ww  w . j  a  va 2 s .com*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            Statement st3 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            st3 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from preparacion_suelo where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery("SELECT * from preparacion_suelo where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE PREPARACIN DE SUELO", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(6);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Tipo de Preparacin",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad Hectreas",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Pases",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Unidad",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda6 = new PdfPCell(new Paragraph("Valor Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);
                    tabla.addCell(celda5);
                    tabla.addCell(celda6);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_preparacions"));
                        tabla.addCell(rs2.getString("tipo_preparacions"));
                        tabla.addCell(rs2.getString("cantidad_hect_horas_preparacions"));
                        tabla.addCell(rs2.getString("pases_preparacions"));
                        tabla.addCell(rs2.getString("valor_unitario_preparacions"));
                        tabla.addCell(rs2.getString("valor_total_preparacions"));

                    }
                    documento.add(tabla);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteQuemaFisica.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w w  w  .j  av  a  2  s.co m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    String num_lote = request.getParameter("num_lote");

    response.setContentType("application/pdf");
    OutputStream out = response.getOutputStream();

    try {
        try {

            Connection con = null;
            Statement st = null;
            Statement st2 = null;
            Statement st3 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root",
                    "9510");

            st = (Statement) con.createStatement();
            st2 = (Statement) con.createStatement();
            st3 = (Statement) con.createStatement();
            rs = st.executeQuery(
                    "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='"
                            + num_lote + "'");
            rs2 = st2.executeQuery("SELECT * from quema_fisica where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery("SELECT * from quema_fisica where num_lote ='" + num_lote + "'");
            if (con != null) {
                Document documento = new Document(A4.rotate());
                PdfWriter writer = PdfWriter.getInstance(documento, out);
                FooterPiePaginaiText footer = new FooterPiePaginaiText();
                writer.setPageEvent(footer);

                documento.open();

                try {

                    Image imagenes = Image.getInstance(
                            "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png");
                    imagenes.setAlignment(Element.ALIGN_RIGHT);
                    imagenes.scaleToFit(200, 200);
                    documento.add(imagenes);

                    //documento.add(imagenes);
                    Paragraph par21 = new Paragraph();
                    Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK);
                    par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip));
                    par21.setAlignment(Element.ALIGN_CENTER);
                    par21.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par21);

                    String nombre = null;
                    String Apellido = null;
                    String cedula = null;
                    while (rs.next()) {
                        nombre = (rs.getString("nombre"));
                        cedula = (rs.getString("cedula"));
                        Apellido = (rs.getString("apellido"));
                    }

                    Paragraph par2 = new Paragraph();
                    Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK);
                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy ");
                    par2.add(new Paragraph("Fecha:  " + dateFormat.format(date), fontfecha));
                    //par2.add(new Paragraph(new Date().toString()));
                    par2.setAlignment(Element.ALIGN_RIGHT);
                    ;
                    documento.add(par2);

                    Paragraph par7 = new Paragraph();
                    Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK);
                    par7.add(new Phrase("Nombre:   " + nombre + "  " + Apellido, fontUsuario));
                    par7.add(new Phrase("\nc.c:   " + cedula, fontUsuario));
                    par7.setAlignment(Element.ALIGN_LEFT);
                    par7.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par7);

                    Paragraph par3 = new Paragraph();
                    Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);
                    par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri));
                    par3.setAlignment(Element.ALIGN_CENTER);
                    par3.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par3);

                } catch (Exception eX) {
                    eX.getMessage();
                }

                try {

                    Paragraph par1 = new Paragraph();
                    Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase(Chunk.NEWLINE));
                    par1.add(new Phrase("REPORTE QUEMA FISICA", fonttitulo));
                    par1.setAlignment(Element.ALIGN_CENTER);
                    par1.add(new Phrase(Chunk.NEWLINE));

                    documento.add(par1);

                    PdfPTable tabla = new PdfPTable(4);
                    FontFactory.registerDirectories();
                    documento.add(new Paragraph("\n"));
                    PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad Mano de Obra",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Mano de Obra",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));

                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_qf"));
                        tabla.addCell(rs2.getString("cantidad_jornales_qf"));
                        tabla.addCell(rs2.getString("valor_unidad_jornal_qf"));
                        tabla.addCell(rs2.getString("valor_total_jornal_qf"));

                    }
                    documento.add(tabla);

                    Paragraph par4 = new Paragraph();

                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    Font fontFooter2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK);
                    par4.add(new Phrase("REPORTE INSUMOS QUEMA FISICA", fontFooter2));
                    par4.setAlignment(Element.ALIGN_CENTER);
                    par4.add(new Phrase(Chunk.NEWLINE));
                    par4.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par4);

                    PdfPTable tabla2 = new PdfPTable(5);
                    FontFactory.registerDirectories();
                    PdfPCell celda10 = new PdfPCell(new Paragraph("Cantidad",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda10.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda20 = new PdfPCell(new Paragraph("Unidad",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda20.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda30 = new PdfPCell(new Paragraph("Valor Unitario",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda30.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda40 = new PdfPCell(new Paragraph("Valor Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda40.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda50 = new PdfPCell(new Paragraph("Costo Total ",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda50.setHorizontalAlignment(Element.ALIGN_CENTER);

                    tabla2.addCell(celda10);
                    tabla2.addCell(celda20);
                    tabla2.addCell(celda30);
                    tabla2.addCell(celda40);
                    tabla2.addCell(celda50);

                    while (rs3.next()) {
                        tabla2.addCell(rs3.getString("cantidad_insumos_qf"));
                        tabla2.addCell(rs3.getString("unidad_insumo_qf"));
                        tabla2.addCell(rs3.getString("valor_unitario_insumo_qf"));
                        tabla2.addCell(rs3.getString("valor_total_insumo_qf"));
                        tabla2.addCell(rs3.getString("valor_total_qf"));
                    }

                    documento.add(tabla2);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                documento.close();

            }
        } catch (Exception e) {
            e.getMessage();
        }

    } finally {
        out.close();
    }
}