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.ReporteQuemaQuimica.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   ww w  .j  a va 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 quema_quimica q JOIN  insumos_quema_quimica i on i.id_quemaq = q.id_quemaq where q.num_lote ='"
                            + num_lote + "'");
            rs3 = st3.executeQuery(
                    "SELECT * from quema_quimica q JOIN  insumos_quema_quimica i on i.id_quemaq = q.id_quemaq where q.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("REPORTE QUEMA QUIMICA", 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)));
                    celda1.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad Mano de Obra",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda2.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Mano de Obra",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda3.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Mano de Obra",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda4.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda5.setHorizontalAlignment(Element.ALIGN_CENTER);
                    celda1.setBackgroundColor(BaseColor.WHITE);
                    celda2.setBackgroundColor(BaseColor.WHITE);
                    celda3.setBackgroundColor(BaseColor.WHITE);
                    celda4.setBackgroundColor(BaseColor.WHITE);
                    celda5.setBackgroundColor(BaseColor.WHITE);
                    tabla.addCell(celda1);
                    tabla.addCell(celda2);
                    tabla.addCell(celda3);
                    tabla.addCell(celda4);
                    tabla.addCell(celda5);
                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_quemaq"));
                        tabla.addCell(rs2.getString("cantidad_mano_obra_quemaq"));
                        tabla.addCell(rs2.getString("valor_mano_obra_quemaq"));
                        tabla.addCell(rs2.getString("valor_total_mano_obra_quemaq"));
                        tabla.addCell(rs2.getString("valor_total_quemaq"));

                    }
                    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 QUIMICA", 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);
                    celda10.setBackgroundColor(BaseColor.WHITE);
                    celda20.setBackgroundColor(BaseColor.WHITE);
                    celda30.setBackgroundColor(BaseColor.WHITE);
                    celda40.setBackgroundColor(BaseColor.WHITE);
                    celda50.setBackgroundColor(BaseColor.WHITE);
                    celda60.setBackgroundColor(BaseColor.WHITE);

                    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.ReporteRiegos.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w  w  w .  j a v  a 2s.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;
            Statement st4 = null;
            ResultSet rs = null;
            ResultSet rs2 = null;
            ResultSet rs3 = null;
            ResultSet rs4 = 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();
            st4 = (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 riego where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery("SELECT * from riego where num_lote ='" + num_lote + "'");
            rs4 = st4.executeQuery("SELECT * from riego 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 RIEGOS", 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 Riego",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad Mano Obra",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Mano Obra",
                            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)));

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

                    while (rs2.next()) {

                        tabla.addCell(rs2.getString("fecha_riego"));
                        tabla.addCell(rs2.getString("tipo_riego"));
                        tabla.addCell(rs2.getString("cantidad_mano_obra_riego"));
                        tabla.addCell(rs2.getString("valor_mano_obra_riego"));
                        tabla.addCell(rs2.getString("total_mano_obra"));

                    }
                    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 RIEGO", 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(7);
                    FontFactory.registerDirectories();
                    PdfPCell celda10 = new PdfPCell(new Paragraph("Tipo de Riego",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda10.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda20 = new PdfPCell(new Paragraph("Cantidad Aceite",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda20.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda30 = new PdfPCell(new Paragraph("Valor Aceite",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda30.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda40 = new PdfPCell(new Paragraph("Valor Total Aceite",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda40.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda50 = new PdfPCell(new Paragraph("Cantidad Combustible",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda50.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda60 = new PdfPCell(new Paragraph("Valor Combustible",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda60.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda70 = new PdfPCell(new Paragraph("Valor Total Combustible",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda70.setHorizontalAlignment(Element.ALIGN_CENTER);

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

                    while (rs3.next()) {
                        tabla2.addCell(rs3.getString("tipo_riego"));
                        tabla2.addCell(rs3.getString("cantidad_aceite"));
                        tabla2.addCell(rs3.getString("valor_aceite"));
                        tabla2.addCell(rs3.getString("total_aceite"));
                        tabla2.addCell(rs3.getString("cantidad_combustible"));
                        tabla2.addCell(rs3.getString("valor_combustible"));
                        tabla2.addCell(rs3.getString("total_combustible_riego"));
                    }

                    documento.add(tabla2);

                    Paragraph par8 = new Paragraph();

                    par8.add(new Phrase(Chunk.NEWLINE));
                    par8.add(new Phrase(Chunk.NEWLINE));
                    par8.add(new Phrase(Chunk.NEWLINE));
                    Font fontFooter4 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.ORANGE);
                    par8.add(new Phrase("REPORTE COSTOS ADICIONALES", fontFooter4));
                    par8.setAlignment(Element.ALIGN_CENTER);
                    par8.add(new Phrase(Chunk.NEWLINE));
                    par8.add(new Phrase(Chunk.NEWLINE));
                    documento.add(par8);

                    PdfPTable tabla3 = new PdfPTable(8);
                    FontFactory.registerDirectories();
                    PdfPCell celda80 = new PdfPCell(new Paragraph("Tipo de Riego",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda80.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda90 = new PdfPCell(new Paragraph("Cantidad Alquiler",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda90.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda100 = new PdfPCell(new Paragraph("Valor Alquiler",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda100.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda110 = new PdfPCell(new Paragraph("Valor Total Alquiler",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda110.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda120 = new PdfPCell(new Paragraph("Valor Tarifa Distrito",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda120.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda130 = new PdfPCell(new Paragraph("Valor Tarifa Corponor",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda130.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda140 = new PdfPCell(new Paragraph("Valor Total Tarifa",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda140.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda150 = new PdfPCell(new Paragraph("Costo Total",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda150.setHorizontalAlignment(Element.ALIGN_CENTER);

                    tabla3.addCell(celda80);
                    tabla3.addCell(celda90);
                    tabla3.addCell(celda100);
                    tabla3.addCell(celda110);
                    tabla3.addCell(celda120);
                    tabla3.addCell(celda130);
                    tabla3.addCell(celda140);
                    tabla3.addCell(celda150);

                    while (rs4.next()) {
                        tabla3.addCell(rs4.getString("tipo_riego"));
                        tabla3.addCell(rs4.getString("cantidad_alquiler_riego"));
                        tabla3.addCell(rs4.getString("valor_alquiler_riego"));
                        tabla3.addCell(rs4.getString("total_alquiler_riego"));
                        tabla3.addCell(rs4.getString("valor_tarifa_districto_riego"));
                        tabla3.addCell(rs4.getString("valor_tarifa_corponor_riego"));
                        tabla3.addCell(rs4.getString("total_tarifa_riego"));
                        tabla3.addCell(rs4.getString("valor_total_riego"));
                    }

                    documento.add(tabla3);

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

                documento.close();

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

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteSiembraManual.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   www. j  a 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 siembra_manual where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery("SELECT * from siembra_manual 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 SIEMBRA MANUAL", 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("Variedad de Semilla",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad de Bultos",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Bultos",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Total Obreros",
                            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_sim"));
                        tabla.addCell(rs2.getString("variedad_semilla_sim"));
                        tabla.addCell(rs2.getString("cantidad_bultos_sim"));
                        tabla.addCell(rs2.getString("precio_bulto_sim"));
                        tabla.addCell(rs2.getString("pago_total_obreros_sim"));

                    }
                    documento.add(tabla);

                    Paragraph par4 = new Paragraph();

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

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

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

                    while (rs3.next()) {
                        tabla2.addCell(rs3.getString("costo_transporte_sim"));
                        tabla2.addCell(rs3.getString("costo_semilla_sim"));
                        tabla2.addCell(rs3.getString("valor_total_sim"));
                    }

                    documento.add(tabla2);

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

                documento.close();

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

    } finally {
        out.close();
    }
}

From source file:ServletsReportesPDF.ReporteSiembraMecanizada.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w ww  .  j a  v  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 siembra_mecanizada where num_lote ='" + num_lote + "'");
            rs3 = st3.executeQuery("SELECT * from siembra_mecanizada 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 SIEMBRA MECANIZADA", 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("Variedad Semilla",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda3 = new PdfPCell(new Paragraph("Costo Semilla",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda4 = new PdfPCell(new Paragraph("Costo Secado Semilla",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda5 = new PdfPCell(new Paragraph("Cantidad Bultos",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    PdfPCell celda6 = new PdfPCell(new Paragraph("Valor Bulto",
                            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_smzd"));
                        tabla.addCell(rs2.getString("variedad_semilla_smzd"));
                        tabla.addCell(rs2.getString("costo_semilla_smzd"));
                        tabla.addCell(rs2.getString("secado_semilla_smzd"));
                        tabla.addCell(rs2.getString("cantidad_bultos_smzd"));
                        tabla.addCell(rs2.getString("valor_bulto_smzd"));

                    }
                    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 MANO DE OBRA SIEMBRA MECANIZADA", 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("Costo Mquina",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda10.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda20 = new PdfPCell(new Paragraph("Cantidad Hectreas",
                            FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK)));
                    celda20.setHorizontalAlignment(Element.ALIGN_CENTER);
                    PdfPCell celda30 = new PdfPCell(new Paragraph("Costo Mano Obra",
                            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)));

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

                    while (rs3.next()) {
                        tabla2.addCell(rs3.getString("costo_mq_sembradora_smzd"));
                        tabla2.addCell(rs3.getString("num_hect_sembradas_smzd"));
                        tabla2.addCell(rs3.getString("costo_mano_obra_smzd"));
                        tabla2.addCell(rs3.getString("valor_total_smzd"));
                    }

                    documento.add(tabla2);

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

                documento.close();

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

    } finally {
        out.close();
    }
}

From source file:ucuenca.edu.sg.controller.util.GenerarActividades.java

public void cabezera() throws DocumentException, BadElementException, IOException {
       ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
       titulo1.setTexto("INFORME DE TAREA POR OBJETIVO");
       titulo1.getElementoRojo();/*from  w ww .  ja  v a 2 s  .c  o m*/
       espacioBlanco.getElemento();
       documento.add(titulo1.getElemento());
       documento.add(espacioBlanco.getElemento());
       documento.add(lineaNormal.getLinea());
       documento.add(espacioBlanco.getElemento());
       documento.add(espacioBlanco.getElemento());

       Image foto = Image.getInstance(getEc().getRealPath("resources") + "/img/golden.jpg");
       foto.scaleToFit(130, 130);
       foto.setAlignment(Chunk.ALIGN_MIDDLE);
       documento.add(foto);

       tablaVertical.limpiar();
       tablaVertical.setTitulos("Nombre Empresa:", "Ubicacion:", "Fecha:");

       tablaVertical.setContenidos(new Object[] { "Gonlden Bringe Corporation S.A ",
               "Florencia Astudillo 1-28 y Av. 12 de Abril", fecha() });

       tablaVertical.setAlineamientos(new int[] { 0, 0 });
       tablaVertical.setAnchoTabla(50);
       tablaVertical.setPosicion(0);
       tablaVertical.setTamanos(new int[] { 30, 70 });
       tablaVertical.llenarTabla(false);
       documento.add(tablaVertical.getTabla());

       documento.add(espacioBlanco.getElemento());
       documento.add(espacioBlanco.getElemento());

   }

From source file:ucuenca.edu.sg.controller.util.ReporteMatrizBSC.java

private void cabezera() throws DocumentException, BadElementException, IOException {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    titulo1.setTexto("REPORTE DE LA MATRIZ DEL CUADRO INTEGRAL");
    titulo1.getElementoRojo();//from ww  w .j  a v  a2 s.c  o  m
    espacioBlanco.getElemento();
    documento.add(titulo1.getElemento());
    documento.add(espacioBlanco.getElemento());
    documento.add(lineaNormal.getLinea());
    documento.add(espacioBlanco.getElemento());
    documento.add(espacioBlanco.getElemento());

    Image foto = Image.getInstance(getEc().getRealPath("resources") + "/img/golden.jpg");
    foto.scaleToFit(130, 130);
    foto.setAlignment(Chunk.ALIGN_MIDDLE);
    documento.add(foto);

    tablaVertical.limpiar();
    tablaVertical.setTitulos("Nombre Empresa:", "Ubicacion:", "Fecha:");

    tablaVertical.setContenidos(new Object[] { "Gonlden Bringe Corporation S.A ",
            "Florencia Astudillo 1-28 y Av. 12 de Abril", fecha() });

    tablaVertical.setAlineamientos(new int[] { 0, 0 });
    tablaVertical.setAnchoTabla(50);
    tablaVertical.setPosicion(0);
    tablaVertical.setTamanos(new int[] { 30, 70 });
    tablaVertical.llenarTabla(false);
    documento.add(tablaVertical.getTabla());

    documento.add(espacioBlanco.getElemento());
    documento.add(espacioBlanco.getElemento());
}

From source file:util.ImageExample.java

public ImageExample(Calendar date, int settings, ArrayList<String> courses, String time, String eventAddress,
        int totalPrice, String comments, boolean kunde) throws Exception {
    this.date = date;
    this.settings = settings;
    this.courses = courses;
    this.time = time;
    this.eventAddress = eventAddress;
    this.totalPrice = totalPrice;
    this.comments = comments;
    this.fileName = "";
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.getAllFonts();/*w w w.  jav  a2  s. c  om*/
    FontFactory.register("C:/Windows/Fonts/ARLRDBD.TTF", "Arial Rounded");
    Font font = FontFactory.getFont("Arial Rounded", 22, Font.NORMAL, new BaseColor(51, 102, 102));
    Document document = new Document();

    System.out.println("Pdf creation startet");
    try {
        if (kunde) {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime()) + ".pdf";
        } else {
            fileName = "grill" + new SimpleDateFormat("dd. MMMMM yyyy hhmm").format(date.getTime())
                    + "Prisliste.pdf";
        }

        FileOutputStream file = new FileOutputStream(new File("C:/Users/Mark/Desktop", fileName));
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();

        Image img = Image.getInstance("src/pictures/cirkles.png");
        img.scaleToFit(277, 277);
        img.setAbsolutePosition(40, PageSize.A4.getHeight() - img.getHeight());
        document.add(img);
        Chunk chunk = new Chunk("Grillmester 'Frankie'", font);
        chunk.setCharacterSpacing(3);
        Paragraph header = new Paragraph(chunk);
        header.setAlignment(Element.ALIGN_RIGHT);
        header.setSpacingBefore(15);
        document.add(header);
        Paragraph title = new Paragraph(
                "Tilbud angende d. " + new SimpleDateFormat("dd. MMMMM yyyy").format(date.getTime()) + ".",
                new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD));
        title.setAlignment(Element.ALIGN_LEFT);
        title.setIndentationLeft(235);
        title.setSpacingBefore(100);
        title.setLeading(17);
        document.add(title);
        Paragraph subtitle = new Paragraph("(Arrangement til " + settings + " personer).",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.ITALIC));
        subtitle.setAlignment(Element.ALIGN_LEFT);
        subtitle.setIndentationLeft(235);
        subtitle.setLeading(17);
        document.add(subtitle);
        Paragraph body = new Paragraph("\n\nDer er aftalt:\n\n", new Font(Font.FontFamily.TIMES_ROMAN, 18));
        body.setAlignment(Element.ALIGN_LEFT);
        body.setIndentationLeft(235);
        body.setLeading(17);
        for (String course : courses) {
            body.add(course + "\n\n");
        }
        body.add("\nServeres klokken " + time + " i " + eventAddress + ".");
        document.add(body);
        Paragraph ending = new Paragraph("\n\n\nPris: " + totalPrice + ",-kr.",
                new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
        ending.setAlignment(Element.ALIGN_LEFT);
        ending.setIndentationLeft(235);
        ending.setLeading(17);
        document.add(ending);
        if (!comments.equals("null")) {
            if (!comments.equals("")) {
                Paragraph comment = new Paragraph("\n\nKommentarer\n" + comments,
                        new Font(Font.FontFamily.TIMES_ROMAN, 18));
                comment.setAlignment(Element.ALIGN_LEFT);
                comment.setIndentationLeft(235);
                comment.setLeading(17);
                document.add(comment);
            }
        }

        Image footerImg = Image.getInstance("src/pictures/grillmester.png");
        footerImg.scaleToFit(210, 210);
        footerImg.setAbsolutePosition(40, 40);
        document.add(footerImg);

        Image img2 = Image.getInstance("src/pictures/Contact.png");
        img2.scaleToFit(250, 250);
        img2.setAbsolutePosition(20, PageSize.A4.getHeight() - img.getHeight() - 250);
        document.add(img2);

        document.close();

        System.out.println("Pdf finish");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getLocalizedMessage());
    }
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImage(User user) throws DocumentException, IOException {
    Image photo_img;
    if (!user.photo.id.equals("")) {
        photo_img = Image//from   ww w .j a va 2s. c  o m
                .getInstance(String.format("https://s3.amazonaws.com/aunclickdelempleo2/" + user.photo.id));
    } else {
        photo_img = Image.getInstance(String.format("public/images/orientation/photo/ic_profile.png"));
    }

    photo_img.setAbsolutePosition(40, 670);
    photo_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    photo_img.setBorder(Image.BOX);
    photo_img.setBorderWidth(10);
    photo_img.setBorderColor(BaseColor.WHITE);
    photo_img.scaleToFit(1000, 130);
    document.add(photo_img);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImageTelephone() throws DocumentException, IOException {
    Image phone_img;
    phone_img = Image.getInstance(String.format("public/images/orientation/cv-templates/CV1/ic_mobile.png"));
    phone_img.setAbsolutePosition(175, 708);
    phone_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    phone_img.setBorder(Image.BOX);
    phone_img.setBorderWidth(10);/*from   ww  w . j  a  va2  s  .c  o m*/
    phone_img.setBorderColor(BaseColor.WHITE);
    phone_img.scaleToFit(1000, 18);
    document.add(phone_img);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addImageEmail() throws DocumentException, IOException {
    Image email_img;
    email_img = Image.getInstance(String.format("public/images/orientation/cv-templates/CV1/ic_mail.png"));
    email_img.setAbsolutePosition(173, 690);
    email_img.setAlignment(Image.LEFT | Image.TEXTWRAP);
    email_img.setBorder(Image.BOX);
    email_img.setBorderWidth(10);//from   w w  w .j a v a  2  s  .  c  o m
    email_img.setBorderColor(BaseColor.WHITE);
    email_img.scaleToFit(1000, 11);
    document.add(email_img);
}