List of usage examples for com.itextpdf.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.itextpdf.text Element ALIGN_LEFT.
Click Source Link
From source file:ServletsReportesPDF.ReporteQuemaQuimica.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www.j a va 2s . 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 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; 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 w w w . j a va 2s .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_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 av a 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_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:sistema.audizio.relatorio.Relatorio.java
public void gerar(Cliente cliente, Processo processo, Veiculo veiculo, Cidade cidade, Bairro bairro, Assessoria assesoria)//from w w w . j a va 2 s .c om throws DocumentException, FileNotFoundException, BadElementException, IOException { String local = "c:\\sistema\\audisio\\relatorios\\" + cliente.getNome() + "-N P-" + processo.getProcesso() + ".pdf"; Document document = new Document(); //PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\ZipNet\\Desktop\\Pdf's\\teste.pdf")); PdfWriter.getInstance(document, new FileOutputStream(local)); document.open(); Font f = new Font(FontFamily.COURIER, 15, Font.NORMAL); Font fgrande = new Font(FontFamily.HELVETICA, 25, Font.ITALIC); Image img = Image.getInstance("c:/sistema/audisio/imagens/relatorio.png"); img.setAlignment(Element.ALIGN_LEFT); Paragraph titulo = new Paragraph("Relatrio de processo", fgrande); Paragraph Clienteente = new Paragraph("DADOS CLIENTE"); Paragraph Processocesso = new Paragraph("DADOS PROCESSO"); Paragraph veiculolo = new Paragraph("DADOS VE?CULO"); titulo.setAlignment(Paragraph.ALIGN_RIGHT); Clienteente.setAlignment(Paragraph.ALIGN_CENTER); Processocesso.setAlignment(Paragraph.ALIGN_CENTER); veiculolo.setAlignment(Paragraph.ALIGN_CENTER); document.add(img); document.add(titulo); document.add(new Paragraph(" ")); document.add(Clienteente); document.add( new Paragraph("______________________________________________________________________________")); document.add(new Paragraph("Nome..: " + cliente.getNome(), f)); document.add(new Paragraph("Celular..: " + cliente.getCelular(), f)); document.add(new Paragraph("Cep..: " + cliente.getCep(), f)); document.add(new Paragraph("Cpf..: " + cliente.getCpf(), f)); document.add(new Paragraph("Uf: " + cliente.getEstado(), f)); document.add(new Paragraph("Endereo..: " + cliente.getEndereco() + ", " + cliente.getNum() + ", " + bairro.getNome() + ", " + cidade.getNome(), f)); document.add(new Paragraph("E-mail..: " + cliente.getEmail(), f)); document.add(new Paragraph(" ")); document.add(veiculolo); document.add( new Paragraph("______________________________________________________________________________")); document.add(new Paragraph(" ")); document.add(new Paragraph("Marca..: " + veiculo.getMarca(), f)); document.add(new Paragraph("Modelo..: " + veiculo.getModelo(), f)); document.add(new Paragraph("Placa..: " + veiculo.getPlaca(), f)); document.add(new Paragraph("Estado..: " + veiculo.getEstado(), f)); document.add(new Paragraph(" ")); document.add(Processocesso); document.add( new Paragraph("______________________________________________________________________________")); document.add(new Paragraph(" ")); document.add(new Paragraph("Processo..: " + processo.getProcesso(), f)); document.add(new Paragraph("Data inicio..: " + processo.getData_inicio(), f)); document.add(new Paragraph("Data trmino..: " + processo.getData_termino(), f)); document.add(new Paragraph("Comarca..: " + processo.getComarca(), f)); document.add(new Paragraph("Vara..: " + processo.getVara(), f)); document.add(new Paragraph("Assesoria..: " + assesoria.getNome(), f)); document.add(new Paragraph("Advogado..: " + assesoria.getNome_advogado(), f)); document.close(); JOptionPane.showMessageDialog(null, "RELATRIO CRIADO COM SUCESSO!\n" + local); try { java.awt.Desktop.getDesktop().open(new File(local)); } catch (IOException ex) { Logger.getLogger(Cadastro.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:storehausimport.SaveToPdf.java
public boolean save(String inputFilePath, String outputFilePath) throws Exception { if (outputFilePath.isEmpty()) { throw new Exception("Trkst parametrs outputFilePath"); }/*w ww.jav a2s . co m*/ if (inputFilePath.isEmpty()) { throw new Exception("Trkst parametrs inputFilePath"); } File inputFile = new File(inputFilePath); Document pdfDoc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(pdfDoc, new FileOutputStream(outputFilePath)); pdfDoc.open(); pdfDoc.setMarginMirroring(true); pdfDoc.setMargins(36, 72, 108, 180); pdfDoc.topMargin(); BaseFont helvetica = BaseFont.createFont("Helvetica", BaseFont.CP1257, BaseFont.NOT_EMBEDDED); Font normal_font = new Font(helvetica, 10, Font.NORMAL); Font bold_font = new Font(); bold_font.setStyle(Font.BOLD); bold_font.setSize(10); pdfDoc.add(new Paragraph("\n")); if (inputFile.exists()) { iStream = new FileInputStream(inputFile); in = new DataInputStream(iStream); is = new InputStreamReader(in); br = new BufferedReader(is); String strLine; while ((strLine = br.readLine()) != null) { Paragraph para = new Paragraph(strLine + "\n", normal_font); para.setAlignment(Element.ALIGN_LEFT); pdfDoc.add(para); } } else { pdfDoc.close(); throw new Exception("Trkst parametrs inputFilePath"); } pdfDoc.close(); } catch (Exception ex) { throw new Exception(ex); } return true; }
From source file:superlaskuttaja.logiikka.PdfExtractor.java
private void muodostaDokumentti(Document document, String laskunNumero, PdfWriter writer) throws DocumentException, SQLException, ParseException { document.open();//from w w w .ja v a 2 s . co m //---------------------------------------------------------------------- PdfPTable table1 = new PdfPTable(7); Font f1 = new Font(Font.FontFamily.HELVETICA, 10); Font f2 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); Font f3 = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); Font f4 = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); ResultSet rs = lataaja.getDbc() .executeQuery("select distinct Laskuttaja.yrityksenNimi, Laskuttaja.katuosoite,\n" + "Laskuttaja.postinumero, Laskuttaja.kaupunki, Lasku.paivays, Laskuttaja.alvTunniste,\n" + "Pankkiviivakoodi.erapaiva, Lasku.viivastyskorko, Pankkiviivakoodi.viiteTarkisteella,\n" + "T.nimi, Lasku.maksuehto, T.katuosoite, Laskuttaja.tilinumeronPankki,\n" + "T.postinumero, T.kaupunki, Laskuttaja.tilinumero, T.email, Laskuttaja.tilinumeronSwiftBic,\n" + "V.nimi, V.katuosoite, V.postinumero, V.kaupunki, V.email, Lasku.lisatiedot,\n" + "T.asiakasnumero, V.asiakasnumero, Laskuttaja.nimi, Laskuttaja.puhelinnumero,\n" + "Laskuttaja.sahkopostiOsoite, Pankkiviivakoodi.pankkiviivakoodi\n" + "from Lasku, Pankkiviivakoodi, Laskuttaja, Suorite, Asiakas T, Asiakas V\n" + "where Lasku.laskunNumero = " + laskunNumero + "\n" + "and Lasku.laskuttaja = Laskuttaja.yrityksenNimi\n" + "and Lasku.laskuttajanVersio = Laskuttaja.versio\n" + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n" + "and Lasku.laskunnumero = Suorite.lasku\n" + "and Suorite.tilaaja = T.asiakasnumero\n" + "and Suorite.tilaajanVersio = T.versio\n" + "and Suorite.vastaanottaja = V.asiakasnumero\n" + "and Suorite.vastaanottajanVersio = V.versio\n" + ""); rs.first(); table1.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin())); table1.setLockedWidth(true); table1.setWidths(new int[] { 370, 100, 73, 100, 73, 100, 179 }); PdfPCell cell; Paragraph p; cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(1), f4); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("LASKU", f4); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(2), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(3) + " " + rs.getString(4), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Pivys", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(pvmFormaatti1.format(pvmFormaatti3.parse(rs.getTimestamp(5).toString())), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Laskun numero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(laskunNumero, f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Alv-tunniste: " + rs.getString(6), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Erpiv", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(pvmFormaatti1.format(pvmFormaatti4.parse(rs.getDate(7).toString())), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Viivstyskorko", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(Integer.toString(rs.getInt(8)) + ".0%", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); //Jos vastaanottaja on sama kuin tilaaja ei laiteta erikseen vastaanottajan tietoja nkyville. if (rs.getInt(25) == rs.getInt(26)) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(10), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Viitenumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(9), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(12), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Maksuehto", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(11), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(14) + " " + rs.getString(15), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Pankki", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(13), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(17), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Tilinumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(16), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Swift/BIC", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(18), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph("Listiedot", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(24), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); document.add(table1); } else { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Palvelun tilaaja", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Viitenumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(9), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(10), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Maksuehto", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(11), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(12), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Pankki", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(13), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(14) + " " + rs.getString(15), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Tilinumero", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(16), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(rs.getString(17), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Swift/BIC", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph(rs.getString(18), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.LIGHT_GRAY); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph("Palvelun vastaanottaja", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(19), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(20), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(21) + " " + rs.getString(22), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(23), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph("Listiedot", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(rs.getString(24), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table1.addCell(cell); table1.completeRow(); document.add(table1); } // Otetaan alemmas tulevia tietoja talteen. String[] alasTulevatTiedot = new String[] { rs.getString(9), rs.getString(1), rs.getString(27), rs.getString(13), rs.getString(2), rs.getString(28), rs.getString(16), rs.getString(3) + " " + rs.getString(4), rs.getString(29), rs.getString(18), rs.getString(30), }; //Muodostetaan suoritteiden taulukko. PdfPTable table2 = new PdfPTable(7); table2.setWidths(new int[] { 370, 100, 73, 100, 73, 100, 179 }); table2.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin())); table2.setLockedWidth(true); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Kuvaus", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Mr", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Yks.", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(" hinta", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Alv %", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Alv ", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph("Yhteens", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(LEFT + BOTTOM + RIGHT + TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); table2.completeRow(); rs = lataaja.getDbc().executeQuery( "select distinct kuvaus, maara, maaranYksikot, aHintaVeroton, alvProsentti, ((alvProsentti / 100.0) * aHintaVeroton * maara) as alvEuroa,\n" + "((1.0 + alvProsentti / 100.0) * aHintaVeroton * maara) as yht, alkuaika\n" + "from Suorite\n" + "where lasku = " + laskunNumero + "\n" + ""); while (rs.next()) { cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getString(1) + " " + pvmFormaatti1.format(pvmFormaatti3.parse(rs.getTimestamp(8).toString())), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(2, 2).toString(), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getString(3), f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(4, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getString(5) + "%", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(6, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(7, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(LEFT + RIGHT); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); table2.completeRow(); } cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(TOP); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table2.addCell(cell); table2.completeRow(); rs = lataaja.getDbc().executeQuery( "select distinct sum(aHintaVeroton * maara), sum((alvProsentti / 100.0) * aHintaVeroton * maara)\n" + "from Suorite\n" + "where lasku = " + laskunNumero + "\n" + ""); rs.first(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Veroton hinta yhteens", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(1, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Arvonlisvero yhteens", f2); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(2, 2).toString() + "", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(7); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(4); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); p = new Paragraph("Yhteens", f3); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); rs = lataaja.getDbc() .executeQuery("select laskunSumma\n" + "from Lasku, Pankkiviivakoodi\n" + "where laskunNumero = " + laskunNumero + "\n" + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n" + ""); rs.first(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(rs.getBigDecimal(1, 2).toString() + "", f3); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table2.addCell(cell); table2.completeRow(); document.add(table2); PdfPTable table3 = new PdfPTable(3); table3.setWidths(new int[] { 1, 1, 1 }); table3.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin())); table3.setLockedWidth(true); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Pyydmme kyttmn maksaessanne viitenumeroa: " + alasTulevatTiedot[0], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBorder(BOTTOM); cell.setBorderColor(BaseColor.BLACK); cell.setBorderWidth(0.2f); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[1], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[2], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[3], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[4], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[5], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[6], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[7], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[8], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(1); p = new Paragraph(alasTulevatTiedot[9], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph(" ", f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_RIGHT); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(3); p = new Paragraph("Virtuaaliviivakoodi: " + alasTulevatTiedot[10], f1); p.setLeading(0, 1); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table3.addCell(cell); table3.completeRow(); table3.writeSelectedRows(0, -1, document.left(document.leftMargin()), table3.getTotalHeight() + document.bottom(document.bottomMargin()), writer.getDirectContent()); //---------------------------------------------------------------------- document.close(); }
From source file:Tables.Printer.java
public void genTrans(TableView gentab, TableColumn name, TableColumn desc, TableColumn amt, TableColumn date, long total, String incOrExp) { try {//from ww w. jav a 2 s.co m // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\general transactions\\GenTransRec" + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(PageSize.A4, 20, 20, 20, 20); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 4f, 5f, 1.5f, 2f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, "General " + incOrExp + " Transaction Table"); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Transaction Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Description of Transaction", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date ", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < gentab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, desc.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amt.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, date.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12); } insertCell(table, "Total ", Element.ALIGN_RIGHT, 2, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 3, bfBold12); insertCell(table, "", Element.ALIGN_RIGHT, 4, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf")); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); iOException.printStackTrace(); } } catch (Exception sd) { sd.printStackTrace(); Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void overdraft(TableView ovTab, TableColumn name, TableColumn amtIssued, TableColumn monthlyDeduction, TableColumn dateIssued, TableColumn startDeduction, TableColumn expDate, TableColumn payStatus, TableColumn expStatus, long totIssue, long totDeduction) { try {/*ww w .j a v a 2s . c om*/ // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\Overdraft\\GenTransRec" + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 2f, 2f, 2f, 3f, 3f, 2f, 1.5f, 1.5f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, "Staff Overdraft Reports"); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Staff Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount Issued", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Monthly Deduction", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date Issued ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Start Deduction", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Expiry Date", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Pay Status", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Expiry Status", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < ovTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amtIssued.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, monthlyDeduction.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, dateIssued.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12); insertCell(table, startDeduction.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, expDate.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, payStatus.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, expStatus.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12); } insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(totIssue), Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, String.valueOf(totDeduction), Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); insertCell(table, "", Element.ALIGN_LEFT, 1, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf")); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (DocumentException | FileNotFoundException sd) { Action showError = Dialogs .create().title("Printer Error").masthead("Errro In Printing File").message(sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }
From source file:Tables.Printer.java
public void supCust_DebtIssue(TableView supIssTab, TableColumn name, TableColumn amtOwed, long total, String title, String fileName) { try {/*from w w w . j av a2 s . c o m*/ // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\default" + app + ".pdf"; if (fileName == "SupplierDebt") { file = "\\Documents\\NjieAB_receipts\\supplier\\debt " + app + ".pdf"; } else if (fileName == "CustumerDebt") { file = "\\Documents\\NjieAB_receipts\\custumer\\debt " + app + ".pdf"; } System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 4f, 5f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, title); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings if (fileName == "SupplierDebt") { insertTableHeading(table, "Supplier Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Total Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12); } else if (fileName == "CustumerDebt") { insertTableHeading(table, "Custumer Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Total Amount Owing", Element.ALIGN_MIDDLE, 1, bfBold12); } table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < supIssTab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amtOwed.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); } insertCell(table, "Total ", Element.ALIGN_RIGHT, 1, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 2, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); } } catch (Exception sd) { Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }