List of usage examples for com.itextpdf.text Image setAlignment
public void setAlignment(final int alignment)
From source file:ro.ldir.chartpackage.GarbagePackageBuilder.java
License:Open Source License
public void writePDF(OutputStream out) throws DocumentException, MalformedURLException, XPathExpressionException, IOException { BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, "Cp1250", BaseFont.NOT_EMBEDDED); final Font hfFont = new Font(bf, 8, Font.NORMAL, BaseColor.GRAY); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, out); writer.setBoxSize("art", new Rectangle(36, 54, 559, 788)); writer.setPageEvent(new PdfPageEventHelper() { private int page = 0; @Override/*from www . j a va2s .c o m*/ public void onEndPage(PdfWriter writer, Document arg1) { page++; Rectangle rect = writer.getBoxSize("art"); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("Pachet mormane - \u00a9 Let's Do It, Romania!", hfFont), (rect.getLeft() + rect.getRight()) / 2, rect.getTop() + 18, 0); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("- " + page + " -", hfFont), (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0); } }); document.open(); document.addAuthor("Let's Do It, Romania!"); document.addTitle("Pachet mormane"); document.addCreationDate(); Font titleFont = new Font(bf, 24, Font.BOLD); Font noteFont = new Font(bf, 12, Font.NORMAL, BaseColor.RED); Font headerFont = new Font(bf, 12, Font.BOLD); Font normalFont = new Font(bf, 11); Font defFont = new Font(bf, 11, Font.BOLD); Paragraph par; int page = 0; for (Garbage garbage : garbages) { par = new Paragraph(); par.setAlignment(Element.ALIGN_CENTER); par.add(new Chunk("Morman " + garbage.getGarbageId() + "\n", titleFont)); par.add(new Chunk("Citi\u0163i cu aten\u0163ie!", noteFont)); document.add(par); par = new Paragraph(); par.setSpacingBefore(20); par.add(new Chunk("1. Date generale\n", headerFont)); par.add(new Chunk("Jude\u0163ul: ", defFont)); par.add(new Chunk(garbage.getCounty().getName() + "\n", normalFont)); par.add(new Chunk("Comuna: ", defFont)); par.add(new Chunk(garbage.getTown().getName() + "\n", normalFont)); if (garbage.getChartedArea() != null) { par.add(new Chunk("Zona cartare: ", defFont)); par.add(new Chunk(garbage.getChartedArea().getName() + "\n", normalFont)); } par.add(new Chunk("Pozi\u0163ie: ", defFont)); par.add(new Chunk(garbage.getY() + ", " + garbage.getX() + "\n", normalFont)); par.add(new Chunk("Descriere:\n", defFont)); par.add(new Phrase(garbage.getDescription() + "\n", normalFont)); par.add(new Chunk("Componen\u0163\u0103 gunoi:\n", defFont)); List list = new List(); list.add(new ListItem( new Chunk("Procent plastic: " + garbage.getPercentagePlastic() + "%", normalFont))); list.add(new ListItem( new Chunk("Procent sticl\u0103: " + garbage.getPercentageGlass() + "%", normalFont))); list.add(new ListItem(new Chunk("Procent metale: " + garbage.getPercentageMetal() + "%", normalFont))); list.add(new ListItem( new Chunk("Procent nereciclabile: " + garbage.getPercentageWaste() + "%", normalFont))); par.add(list); document.add(par); par = new Paragraph(); par.setSpacingBefore(20); par.add(new Chunk("2. Indica\u0163ii rutiere\n", headerFont)); Image img = Image.getInstance(getImage(garbage)); img.scaleToFit((float) (PageSize.A4.getWidth() * .75), (float) (PageSize.A4.getHeight() * .75)); img.setAlignment(Element.ALIGN_CENTER); par.add(img); document.add(par); if (page < garbages.size() - 1) document.newPage(); page++; } document.close(); }
From source file:Servicios.ArchivoOrden.java
public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata) { try {/* ww w . j ava 2s.c o m*/ if (type.equals(ScannerIOMetadata.ACQUIRED)) { //****************obtenemos la nueva fecha Date fecha_orden = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha_orden); String[] fecha = valor.split("-"); String[] hora = fecha[2].split(":"); String[] aux = hora[0].split(" "); fecha[2] = aux[0]; hora[0] = aux[1]; Calendar calendario = Calendar.getInstance(); calendario.set(Integer.parseInt(fecha[2]), Integer.parseInt(fecha[1]) - 1, Integer.parseInt(fecha[0]), Integer.parseInt(hora[0]), Integer.parseInt(hora[1]), Integer.parseInt(hora[2])); boolean op = true; do { String nombre = ""; File destino = null; nombre = javax.swing.JOptionPane.showInputDialog(null, "Guardar como:"); if (nombre == null) nombre = ""; if (nombre.compareToIgnoreCase("") != 0) { File archivo = new File(ruta + "ordenes/" + orden + "/archivos/" + nombre + ".pdf"); if (archivo.exists()) { int opt = JOptionPane.showConfirmDialog(this, "El archivo ya existe desea remplazarlo", "Alerta", JOptionPane.YES_NO_OPTION); if (opt == 0) { BufferedImage image = metadata.getImage(); Document document = new Document(PageSize.LETTER, 36, 36, 54, 36); PdfWriter.getInstance(document, new FileOutputStream( ruta + "ordenes/" + orden + "/archivos/" + nombre + ".pdf")); document.open(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write((RenderedImage) image, "jpg", baos); baos.flush(); byte[] imagedata = baos.toByteArray(); Image imagen = Image.getInstance(imagedata); imagen.setAlignment(Element.ALIGN_CENTER); imagen.scaleAbsolute(PageSize.LETTER.getWidth(), PageSize.LETTER.getHeight()); document.add(imagen); document.close(); Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction().begin(); int id = -1; Archivo ar = (Archivo) session.createCriteria(Archivo.class) .add(Restrictions.eq("orden.idOrden", ord.getIdOrden())) .add(Restrictions.eq("nombreDocumento", archivo.getName())) .setMaxResults(1).uniqueResult(); if (ar != null) { ar.setFechaDocumento(calendario.getTime()); session.update(ar); } else { ar = new Archivo(); Archivo img = new Archivo(ord, archivo.getName(), calendario.getTime()); ord = (Orden) session.get(Orden.class, Integer.parseInt(orden)); ord.addArchivo(img); session.save(ord); } session.getTransaction().commit(); } catch (Exception e) { System.out.println(e); } if (session != null) if (session.isOpen()) session.close(); File file = new File(ruta + "ordenes/" + orden + "/archivos/" + nombre + ".pdf"); Desktop.getDesktop().open(file); op = false; } } else { BufferedImage image = metadata.getImage(); Document document = new Document(PageSize.LETTER, 36, 36, 54, 36); PdfWriter.getInstance(document, new FileOutputStream( ruta + "ordenes/" + orden + "/archivos/" + nombre + ".pdf")); document.open(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write((RenderedImage) image, "jpg", baos); baos.flush(); byte[] imagedata = baos.toByteArray(); Image imagen = Image.getInstance(imagedata); imagen.setAlignment(Element.ALIGN_CENTER); imagen.scaleAbsolute(PageSize.LETTER.getWidth(), PageSize.LETTER.getHeight()); document.add(imagen); document.close(); Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction().begin(); int id = -1; Archivo ar = (Archivo) session.createCriteria(Archivo.class) .add(Restrictions.eq("orden.idOrden", ord.getIdOrden())) .add(Restrictions.eq("nombreDocumento", archivo.getName())).setMaxResults(1) .uniqueResult(); ar = new Archivo(); Archivo img = new Archivo(ord, archivo.getName(), calendario.getTime()); ord = (Orden) session.get(Orden.class, Integer.parseInt(orden)); ord.addArchivo(img); session.save(ord); session.getTransaction().commit(); } catch (Exception e) { System.out.println(e); } if (session != null) if (session.isOpen()) session.close(); File file = new File(ruta + "ordenes/" + orden + "/archivos/" + nombre + ".pdf"); Desktop.getDesktop().open(file); op = false; } } } while (op); cargaArchivos(); } else if (type.equals(ScannerIOMetadata.STATECHANGE)) { System.out.println(metadata.getStateStr()); } else if (type.equals(ScannerIOMetadata.EXCEPTION)) { metadata.getException().printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:servlet.AdministrarRestriccion.java
public void genDocTren(HttpServletRequest request, HttpServletResponse response) throws Exception { int linea = Integer.parseInt(request.getParameter("idLinea")); //PrintWriter salida = response.getWriter(); HttpSession session = request.getSession(); // PrintWriter out = response.getWriter(); Usuario usr = (Usuario) session.getAttribute("usuario"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {// ww w . ja va 2 s .c o m String nota = new String(request.getParameter("nota").getBytes(), "UTF-8"); String nota2 = new String(request.getParameter("nota2").getBytes(), "UTF-8"); MaterialRodanteJpaController mrjc = new MaterialRodanteJpaController(Conex.getEmf()); MaterialRodante mr = mrjc .findMaterialRodante(Integer.parseInt(request.getParameter("materialRodante"))); String comunicaciones = new String(request.getParameter("comunicaciones").getBytes(), "UTF-8"); String instrucciones = new String(request.getParameter("instrucciones").getBytes(), "UTF-8"); String precauciones = new String(request.getParameter("precauciones").getBytes(), "UTF-8"); String nombre = new String(request.getParameter("nombre").getBytes(), "UTF-8"); String vigencia = request.getParameter("vigencia"); String[] fecha = vigencia.split("-"); LineaJpaController ljc = new LineaJpaController(Conex.getEmf()); Linea l = ljc.findLinea(linea); Document documento = new Document(PageSize.A4); com.itextpdf.text.Font arialNegrita = FontFactory.getFont("arial", 9, Font.BOLD); com.itextpdf.text.Font arial = FontFactory.getFont("arial", 9, Font.PLAIN); com.itextpdf.text.Font saltoDeLinea = FontFactory.getFont("arial", 5, Font.BOLD); Paragraph parrafo = new Paragraph(); int numResAs = 0; int numResDes = 0; RestriccionJpaController rjc = new RestriccionJpaController(Conex.getEmf()); List<Restriccion> restDes = rjc.buscarIdLineaDescendenteDocTren(linea, l.getVelocidadLinea()); List<Restriccion> restAsc = rjc.buscarIdLineaAscendenteDocTren(linea, l.getVelocidadLinea()); int restAscTotal = restAsc.size() - 1; int restDescTotal = restDes.size() - 1; System.out.println(restAscTotal); System.out.println(restDescTotal); PdfWriter.getInstance(documento, baos); documento.open(); do { try { URL url = getClass().getResource("/img/cintillo_s1.png"); Image foto = Image.getInstance(url); foto.scaleToFit(500, 70); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita)); documento.add(new Paragraph( "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes", arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable tabla = new PdfPTable(1); tabla.setHorizontalAlignment(10); tabla.setWidthPercentage(100f); tabla.addCell(new Paragraph("Operaciones Del Tren: circular a una velocidad no mayor de " + l.getVelocidadLinea() + " Km/h", arial)); tabla.addCell(new Paragraph("Nota: " + nota, arial)); //tabla.getDefaultCell().setBorder(2); if (numResAs < restAscTotal) { tabla.getDefaultCell().setBorderWidthBottom(0); tabla.addCell(new Paragraph("Restricciones Ascendentes ", arialNegrita)); } tabla.getDefaultCell().setBorderColorBottom(BaseColor.WHITE); int c = 0; for (int i = numResAs; i <= restAscTotal; i++) { if (c > 30) { break; } // System.out.println("imrimiento asc: "+numResAs); int pkI = (int) (restAsc.get(numResAs).getProgInicio() / 1000); int pkI1 = (int) (((restAsc.get(numResAs).getProgInicio() / 1000) - pkI) * 1000); int pkF = (int) (restAsc.get(numResAs).getProgFinal() / 1000); int pkF1 = (int) (((restAsc.get(numResAs).getProgFinal() / 1000) - pkF) * 1000); tabla.getDefaultCell().setBorder(14); tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1 + " circular a una velocidad no mayor de " + restAsc.get(numResAs).getVelocidadMaxAscendente() + " " + restAsc.get(numResAs).getObservacion(), arial)); numResAs++; c++; } if (c < 30) { tabla.getDefaultCell().setBorderWidthBottom(1); tabla.getDefaultCell().setBorderWidthTop(1); tabla.getDefaultCell().setBorder(14); tabla.addCell(new Paragraph("Restricciones Descendentes ", arialNegrita)); } int d = c; if (c < 30) { for (int i = numResDes; i <= restDescTotal; i++) { if (d > 30) { break; } tabla.getDefaultCell().setBorder(14); tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); int pkI = (int) (restDes.get(numResDes).getProgFinal() / 1000); int pkI1 = (int) (((restDes.get(numResDes).getProgFinal() / 1000) - pkI) * 1000); int pkF = (int) (restDes.get(numResDes).getProgInicio() / 1000); int pkF1 = (int) (((restDes.get(numResDes).getProgInicio() / 1000) - pkF) * 1000); tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1 + " circular a una velocidad no mayor de " + restDes.get(numResDes).getVelocidadMaxDescendente() + " " + restDes.get(numResDes).getObservacion(), arial)); numResDes++; d++; } } int espacios = d; while (espacios < 30) { tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); tabla.addCell(new Paragraph(" ", arial)); espacios++; } tabla.getDefaultCell().setBorder(15); tabla.getDefaultCell().setBorderWidthBottom(1); tabla.getDefaultCell().setBorderWidthTop(1); tabla.getDefaultCell().setMinimumHeight(50f); tabla.addCell(new Paragraph("Instrucciones: " + instrucciones, arial)); tabla.addCell(new Paragraph("Comunicaciones: " + comunicaciones, arial)); tabla.addCell(new Paragraph("Precauciones: " + precauciones, arial)); tabla.getDefaultCell().setMinimumHeight(10f); tabla.addCell(new Paragraph("Vigencia A Partir De: " + fecha[0] + "/" + fecha[1] + "/" + fecha[2], arial)); tabla.getDefaultCell().setBorder(1); Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER, "Realizado Por: " + usr.toString() + " - Gerencia de Gestin de Trfico", arialNegrita); preface.setAlignment(Element.ALIGN_CENTER); tabla.addCell(preface); tabla.getDefaultCell().setBorder(0); tabla.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); preface = new Paragraph(Paragraph.ALIGN_CENTER, "EL NO CUMPLIR CON LAS LIMITACIONES PRESCRITAS EN ESTE" + " DOCUMENTO VA EN CONTRA DE LA SEGURIDAD EN LA CIRCULACIN, POR LO TANTO SER? MOTIVO DE SANCIN", FontFactory.getFont("arial", 8f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "Nota: Informacin sustentada con el informe tcnico " + "de limitaciones de velocidad, emitido por el CCF (Centro de Control de Fallas)", FontFactory.getFont("arial", 8f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "Sentido Ascendente: Sentido en el cual aumenta la progresiva ej: 0+0 -> 41+000 -- Sentido Descendente: Sentido en el cual disminuye la progresiva ej: 41+000 -> 0+0 ", FontFactory.getFont("arial", 6f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "En la lnea Caracas-Cua el sentido ASCENDENTE corresponde a la V?A PAR y el DESCENDENTE a la V?A IMPAR", FontFactory.getFont("arial", 6f)); tabla.addCell(preface); documento.add(tabla); if (numResAs < restAscTotal || numResDes < restDescTotal) { documento.newPage(); } } while (numResAs < restAscTotal || numResDes < restDescTotal); System.out.println("Termine"); //CARACTER?STICAS DE MATERIAL RODANTE documento.newPage(); try { URL url = getClass().getResource("/img/cintillo_s1.png"); Image foto = Image.getInstance(url); foto.scaleToFit(500, 70); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita)); documento.add(new Paragraph( "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes", arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add( new Paragraph("CARACTER?STICAS DE LA UNIDAD: " + mr.getNombreMaterialRodante(), arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable tablaMT = new PdfPTable(2); tablaMT.addCell(new Paragraph("ITEM", arialNegrita)); tablaMT.addCell(new Paragraph("DESCRIPCIN", arialNegrita)); tablaMT.addCell(new Paragraph("Nmero de Unidades Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getNumeroRemolque() + " Unidades", arial)); tablaMT.addCell(new Paragraph("Nmero de Unidades Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getNumeroMotriz() + " Unidades", arial)); tablaMT.addCell(new Paragraph("Longitud Total", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudTotal() + " m", arial)); tablaMT.addCell(new Paragraph("Longitud Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudRemolque() + " m", arial)); tablaMT.addCell(new Paragraph("Longitud Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudMotriz() + " m", arial)); tablaMT.addCell(new Paragraph("Alto x Ancho Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getAltoXAnchoMotriz() + " m", arial)); tablaMT.addCell(new Paragraph("Alto x Ancho Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getAltoXAnchoRemolque() + " m", arial)); tablaMT.addCell(new Paragraph("Masa o Tara Total", arial)); tablaMT.addCell(new Paragraph(mr.getMasa() + " t", arial)); tablaMT.addCell(new Paragraph("Masa Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getMasaRemolque() + " t", arial)); tablaMT.addCell(new Paragraph("Masa Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getMasaMotriz() + " t", arial)); tablaMT.addCell(new Paragraph("Frenado", arial)); tablaMT.addCell(new Paragraph(mr.getFrenadoDescripcion() + "", arial)); tablaMT.addCell(new Paragraph("Trocha", arial)); tablaMT.addCell(new Paragraph(l.getTrocha() + " m", arial)); tablaMT.addCell(new Paragraph("Velocidad Comercial", arial)); tablaMT.addCell(new Paragraph(mr.getVelocidadOperativa() + " Km/h", arial)); tablaMT.addCell(new Paragraph("Aceleracin Mx.", arial)); tablaMT.addCell(new Paragraph(mr.getAceleracionMax() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Desaceleracin de Servicio", arial)); tablaMT.addCell(new Paragraph(mr.getDesaceleracionMax() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Desaceleracion de Emergencia", arial)); tablaMT.addCell(new Paragraph(mr.getDesaceleracionEmergencia() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Voltaje", arial)); tablaMT.addCell(new Paragraph(mr.getVoltaje() + " V", arial)); tablaMT.addCell(new Paragraph("Voltaje de Bateras", arial)); tablaMT.addCell(new Paragraph(mr.getVoltajeBateria() + " V", arial)); tablaMT.addCell(new Paragraph("Presin de Trabajo", arial)); tablaMT.addCell(new Paragraph(mr.getPresionTrabajo() + "", arial)); if (mr.getSubTipo().equals("Tren de Viajeros")) { tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " pasajeros", arial)); tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " pasajeros", arial)); tablaMT.addCell(new Paragraph("Capacidad Total", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " pasajeros", arial)); } else { tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " t", arial)); tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " t", arial)); tablaMT.addCell(new Paragraph("Capacidad Total", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " t", arial)); } documento.add(tablaMT); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); try { URL url = getClass().getResource("/img/" + request.getParameter("materialRodante") + ".jpg"); Image foto = Image.getInstance(url); foto.scaleToFit(300, 300); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable t = new PdfPTable(1); t.setWidthPercentage(100f); t.addCell("Nota: " + nota2); documento.add(t); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER, "Realizado Por: " + usr.toString(), arialNegrita); documento.add(preface); documento.close(); response.addHeader("Content-Disposition", "attachment; filename=DocumentoDeTren.pdf"); response.addHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.addHeader("Pragma", "public"); response.setContentType("application/pdf"); DataOutput output = new DataOutputStream(response.getOutputStream()); byte[] bytes = baos.toByteArray(); response.setContentLength(bytes.length); for (int i = 0; i < bytes.length; i++) { output.writeByte(bytes[i]); } } catch (Exception e) { e.printStackTrace(); // salida.print("http://localhost:8084/MODULO2.3/img/error.png"); } }
From source file:ServletsReportesPDF.ReporteAbonadas.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww . ja 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 { Statement st = null; Statement st2 = null; Statement st3 = null; Statement st4 = null; Statement st5 = null; ResultSet rs = null; ResultSet rs2 = null; ResultSet rs3 = null; ResultSet rs4 = null; ResultSet rs5 = null; java.sql.Connection con = new ConexionBD().ConexionBD2(); st = (Statement) con.createStatement(); st2 = (Statement) con.createStatement(); st3 = (Statement) con.createStatement(); st4 = (Statement) con.createStatement(); st5 = (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 abonada a JOIN insumos_abonada i on i.id_abonada = a.id_abonada where a.num_lote ='" + num_lote + "'"); rs3 = st3.executeQuery( "SELECT * from abonada a JOIN insumos_abonada i on i.id_abonada = a.id_abonada where a.num_lote ='" + num_lote + "'"); rs4 = st4.executeQuery("select * from abonada where num_lote = '" + num_lote + "'"); rs5 = st5.executeQuery( "SELECT * from abonada a JOIN insumos_abonada i on i.id_abonada = a.id_abonada where a.num_lote ='" + num_lote + "'"); if (con != null) { Document documento = new Document(A4.rotate()); PdfWriter writer = PdfWriter.getInstance(documento, out); FooterPiePaginaiText footer = new FooterPiePaginaiText(); writer.setPageEvent(footer); documento.open(); try { Image imagenes = Image.getInstance( "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png"); imagenes.setAlignment(Element.ALIGN_RIGHT); imagenes.scaleToFit(120, 120); documento.add(imagenes); //documento.add(imagenes); Paragraph par21 = new Paragraph(); Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK); par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip)); par21.setAlignment(Element.ALIGN_CENTER); par21.add(new Phrase(Chunk.NEWLINE)); documento.add(par21); String nombre = null; String Apellido = null; String cedula = null; while (rs.next()) { nombre = (rs.getString("nombre")); cedula = (rs.getString("cedula")); Apellido = (rs.getString("apellido")); } Paragraph par2 = new Paragraph(); Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy "); par2.add(new Paragraph("Fecha: " + dateFormat.format(date), fontfecha)); //par2.add(new Paragraph(new Date().toString())); par2.setAlignment(Element.ALIGN_RIGHT); ; documento.add(par2); Paragraph par7 = new Paragraph(); Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK); par7.add(new Phrase("Nombre: " + nombre + " " + Apellido, fontUsuario)); par7.add(new Phrase("\nc.c: " + cedula, fontUsuario)); par7.setAlignment(Element.ALIGN_LEFT); par7.add(new Phrase(Chunk.NEWLINE)); documento.add(par7); Paragraph par3 = new Paragraph(); Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri)); par3.setAlignment(Element.ALIGN_CENTER); par3.add(new Phrase(Chunk.NEWLINE)); documento.add(par3); } catch (Exception eX) { eX.getMessage(); } try { Paragraph par1 = new Paragraph(); Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase("REPORTE ABONADAS", fonttitulo)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); PdfPTable tabla = new PdfPTable(6); FontFactory.registerDirectories(); documento.add(new Paragraph("\n")); PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda2 = new PdfPCell(new Paragraph("Tipo Abonada", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad Bultos", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda4 = new PdfPCell(new Paragraph("Costo Bulto", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Total Bultos", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda6 = new PdfPCell(new Paragraph("Unidad", 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_abonada")); tabla.addCell(rs2.getString("nombre_abonada")); tabla.addCell(rs2.getString("cantidad_bulto_aplicado_abonada")); tabla.addCell(rs2.getString("costo_unitario_bulto_abonada")); tabla.addCell(rs2.getString("valor_total_bulto_abonada")); tabla.addCell(rs2.getString("unidad_mano_obra_abonada")); } documento.add(tabla); } catch (Exception eX) { eX.getMessage(); } try { 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 ABONADAS", 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(3); FontFactory.registerDirectories(); PdfPCell celda10 = new PdfPCell(new Paragraph("Cantidad Mano Obra", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda10.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda20 = new PdfPCell(new Paragraph("Costo Mano Obra", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda20.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda30 = new PdfPCell(new Paragraph("Valor Total Mano Obra", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda30.setHorizontalAlignment(Element.ALIGN_CENTER); tabla2.addCell(celda10); tabla2.addCell(celda20); tabla2.addCell(celda30); while (rs3.next()) { tabla2.addCell(rs3.getString("cantidad_mano_obra_abonada")); tabla2.addCell(rs3.getString("costo_unitario_mano_obra_abonada")); tabla2.addCell(rs3.getString("valor_total_mano_obra_abonada")); } documento.add(tabla2); } catch (Exception eX) { eX.getMessage(); } try { Paragraph par11 = new Paragraph(); par11.add(new Phrase(Chunk.NEWLINE)); par11.add(new Phrase(Chunk.NEWLINE)); par11.add(new Phrase(Chunk.NEWLINE)); Font fontFooter3 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par11.add(new Phrase("OTROS", fontFooter3)); par11.setAlignment(Element.ALIGN_CENTER); par11.add(new Phrase(Chunk.NEWLINE)); par11.add(new Phrase(Chunk.NEWLINE)); documento.add(par11); PdfPTable tabla3 = new PdfPTable(4); FontFactory.registerDirectories(); PdfPCell celda21 = new PdfPCell(new Paragraph("Cantidad Transporte", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda21.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda22 = new PdfPCell(new Paragraph("Costo Transporte", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda22.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda23 = new PdfPCell(new Paragraph("Valor Total Transporte", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda23.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda24 = new PdfPCell(new Paragraph("Valor Total Abonada", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda24.setHorizontalAlignment(Element.ALIGN_CENTER); tabla3.addCell(celda21); tabla3.addCell(celda22); tabla3.addCell(celda23); tabla3.addCell(celda24); while (rs4.next()) { tabla3.addCell(rs4.getString("cantidad_transporte_abonada")); tabla3.addCell(rs4.getString("costo_transporte_abonada")); tabla3.addCell(rs4.getString("valor_total_transporte_abonada")); tabla3.addCell(rs4.getString("valor_total_abonada")); } documento.add(tabla3); } catch (Exception eX) { eX.getMessage(); } try { Paragraph par7 = new Paragraph(); par7.add(new Phrase(Chunk.NEWLINE)); par7.add(new Phrase(Chunk.NEWLINE)); par7.add(new Phrase(Chunk.NEWLINE)); Font fontFooter4 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par7.add(new Phrase("REPORTE INSUMOS ABONADAS", fontFooter4)); par7.setAlignment(Element.ALIGN_CENTER); par7.add(new Phrase(Chunk.NEWLINE)); par7.add(new Phrase(Chunk.NEWLINE)); documento.add(par7); PdfPTable tabla4 = new PdfPTable(6); FontFactory.registerDirectories(); PdfPCell celda31 = new PdfPCell(new Paragraph("Tipo", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda31.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda32 = new PdfPCell(new Paragraph("Nombre", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda32.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda33 = new PdfPCell(new Paragraph("Cantidad", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda33.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda34 = new PdfPCell(new Paragraph("Unidad", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda34.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda35 = new PdfPCell(new Paragraph("Valor Unitario", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda35.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda36 = new PdfPCell(new Paragraph("Valor Total", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda36.setHorizontalAlignment(Element.ALIGN_CENTER); tabla4.addCell(celda31); tabla4.addCell(celda32); tabla4.addCell(celda33); tabla4.addCell(celda34); tabla4.addCell(celda35); tabla4.addCell(celda36); while (rs5.next()) { tabla4.addCell(rs5.getString("tipo_insumo")); tabla4.addCell(rs5.getString("nombre_insumo")); tabla4.addCell(rs5.getString("cantidad_insumo")); tabla4.addCell(rs5.getString("unidad_insumo")); tabla4.addCell(rs5.getString("valor_unitario_insumo")); tabla4.addCell(rs5.getString("valor_total_insumos")); } documento.add(tabla4); } catch (Exception e) { e.printStackTrace(); } documento.close(); } } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:ServletsReportesPDF.ReporteCortaBultos.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww .j a v a2 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; Statement st5 = null; ResultSet rs = null; ResultSet rs2 = null; ResultSet rs3 = null; ResultSet rs4 = null; ResultSet rs5 = 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(); st5 = (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 corta_bultos where num_lote ='" + num_lote + "'"); rs3 = st3.executeQuery("SELECT * from corta_bultos where num_lote ='" + num_lote + "'"); rs4 = st4.executeQuery("SELECT * from corta_bultos where num_lote ='" + num_lote + "'"); rs5 = st5.executeQuery("SELECT * from corta_bultos where num_lote ='" + num_lote + "'"); if (con != null) { Document documento = new Document(A4.rotate()); PdfWriter writer = PdfWriter.getInstance(documento, out); FooterPiePaginaiText footer = new FooterPiePaginaiText(); writer.setPageEvent(footer); documento.open(); try { Image imagenes = Image.getInstance( "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png"); imagenes.setAlignment(Element.ALIGN_RIGHT); imagenes.scaleToFit(120, 120); documento.add(imagenes); //documento.add(imagenes); Paragraph par21 = new Paragraph(); Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK); par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip)); par21.setAlignment(Element.ALIGN_CENTER); par21.add(new Phrase(Chunk.NEWLINE)); documento.add(par21); String nombre = null; String Apellido = null; String cedula = null; while (rs.next()) { nombre = (rs.getString("nombre")); cedula = (rs.getString("cedula")); Apellido = (rs.getString("apellido")); } Paragraph par2 = new Paragraph(); Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy "); par2.add(new Paragraph("Fecha: " + dateFormat.format(date), fontfecha)); //par2.add(new Paragraph(new Date().toString())); par2.setAlignment(Element.ALIGN_RIGHT); ; documento.add(par2); Paragraph par7 = new Paragraph(); Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK); par7.add(new Phrase("Nombre: " + nombre + " " + Apellido, fontUsuario)); par7.add(new Phrase("\nc.c: " + cedula, fontUsuario)); par7.setAlignment(Element.ALIGN_LEFT); par7.add(new Phrase(Chunk.NEWLINE)); documento.add(par7); Paragraph par3 = new Paragraph(); Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri)); par3.setAlignment(Element.ALIGN_CENTER); par3.add(new Phrase(Chunk.NEWLINE)); documento.add(par3); } catch (Exception eX) { eX.getMessage(); } try { Paragraph par1 = new Paragraph(); Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase("REPORTE CORTA POR BULTOS", fonttitulo)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); Paragraph par2 = new Paragraph(); Font fonttitulo2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase("REPORTE CORTO DE MAQUINA LLANTA Y ORUGA", fonttitulo2)); par2.setAlignment(Element.ALIGN_CENTER); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); PdfPTable tabla = new PdfPTable(7); FontFactory.registerDirectories(); documento.add(new Paragraph("\n")); PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad (Llanta)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Unidad (Llanta)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Total (Llanta)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda5 = new PdfPCell(new Paragraph("Cantidad (Oruga)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda6 = new PdfPCell(new Paragraph("Valor Unidad (Oruga)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda7 = new PdfPCell(new Paragraph("Valor Total (Oruga)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); tabla.addCell(celda1); tabla.addCell(celda2); tabla.addCell(celda3); tabla.addCell(celda4); tabla.addCell(celda5); tabla.addCell(celda6); tabla.addCell(celda7); while (rs2.next()) { tabla.addCell(rs2.getString("fecha_crb")); tabla.addCell(rs2.getString("cantidad_mq_llanta_crb")); tabla.addCell(rs2.getString("valor_mq_llanta_crb")); tabla.addCell(rs2.getString("valor_total_mq_llanta_crb")); tabla.addCell(rs2.getString("cantidad_mq_oruga_crb")); tabla.addCell(rs2.getString("valor_mq_oruga_crb")); tabla.addCell(rs2.getString("valor_total_mq_oruga_crb")); } 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 COSTOS DE LLENADOR, TRACTOR Y BULTEADOR", 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(9); FontFactory.registerDirectories(); PdfPCell celda10 = new PdfPCell(new Paragraph("Cantidad (Llenador)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda10.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda20 = new PdfPCell(new Paragraph("Valor Unidad (Llenador)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda20.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda30 = new PdfPCell(new Paragraph("Valor Total (Llenador)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda30.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda40 = new PdfPCell(new Paragraph("Cantidad (Tractor)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda40.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda50 = new PdfPCell(new Paragraph("Valor Unidad (Tractor)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda50.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda60 = new PdfPCell(new Paragraph("Valor Total (Tractor)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda60.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda70 = new PdfPCell(new Paragraph("Cantidad (Bulteador)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda70.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda80 = new PdfPCell(new Paragraph("Valor Unidad (Bulteador)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda80.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda90 = new PdfPCell(new Paragraph("Valor Total (Bulteador)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda90.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); tabla2.addCell(celda80); tabla2.addCell(celda90); while (rs3.next()) { tabla2.addCell(rs3.getString("cantidad_llenador_crb")); tabla2.addCell(rs3.getString("valor_llenador_crb")); tabla2.addCell(rs3.getString("valor_total_llenador_crb")); tabla2.addCell(rs3.getString("cantidad_tractor_crb")); tabla2.addCell(rs3.getString("valor_tractor_crb")); tabla2.addCell(rs3.getString("valor_total_tractor_crb")); tabla2.addCell(rs3.getString("cantidad_bulteador_crb")); tabla2.addCell(rs3.getString("valor_bulteador_crb")); tabla2.addCell(rs3.getString("valor_total_bulteador_crb")); } 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.BLACK); par8.add(new Phrase("REPORTE COSTOS DE FLETE", 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(3); FontFactory.registerDirectories(); PdfPCell celda100 = new PdfPCell(new Paragraph("Cantidad (Flete)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda100.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda110 = new PdfPCell(new Paragraph("Valor Unidad (Flete)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda110.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda120 = new PdfPCell(new Paragraph("Valor Total (Flete)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda120.setHorizontalAlignment(Element.ALIGN_CENTER); tabla3.addCell(celda100); tabla3.addCell(celda110); tabla3.addCell(celda120); while (rs4.next()) { tabla3.addCell(rs4.getString("cantidad_flete_crb")); tabla3.addCell(rs4.getString("valor_flete_crb")); tabla3.addCell(rs4.getString("valor_total_flete_crb")); } documento.add(tabla3); Paragraph par9 = new Paragraph(); par9.add(new Phrase(Chunk.NEWLINE)); par9.add(new Phrase(Chunk.NEWLINE)); par9.add(new Phrase(Chunk.NEWLINE)); Font fontFooter5 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par9.add(new Phrase("REPORTE COSTOS ADICIONALES", fontFooter5)); par9.setAlignment(Element.ALIGN_CENTER); par9.add(new Phrase(Chunk.NEWLINE)); par9.add(new Phrase(Chunk.NEWLINE)); documento.add(par9); PdfPTable tabla4 = new PdfPTable(6); FontFactory.registerDirectories(); PdfPCell celda130 = new PdfPCell(new Paragraph("Valor Cabuya O Nylon", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda130.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda140 = new PdfPCell(new Paragraph("Valor Celadura Mquina", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda140.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda150 = new PdfPCell(new Paragraph("Valor Alimentacin", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda150.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda160 = new PdfPCell(new Paragraph("Valor Administracin", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda160.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda170 = new PdfPCell(new Paragraph("Valor Transporte Mquina Oruga", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda170.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda180 = new PdfPCell(new Paragraph("Costo Total", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda180.setHorizontalAlignment(Element.ALIGN_CENTER); tabla4.addCell(celda130); tabla4.addCell(celda140); tabla4.addCell(celda150); tabla4.addCell(celda160); tabla4.addCell(celda170); tabla4.addCell(celda180); while (rs5.next()) { tabla4.addCell(rs5.getString("valor_cabuya_nylon_crb")); tabla4.addCell(rs5.getString("valor_celaduria_maquina_crb")); tabla4.addCell(rs5.getString("valor_alimentacion_crb")); tabla4.addCell(rs5.getString("valor_administracion_crb")); tabla4.addCell(rs5.getString("valor_maquina_oruga_crb")); tabla4.addCell(rs5.getString("valor_total_crb")); } documento.add(tabla4); } catch (Exception e) { e.printStackTrace(); } documento.close(); } } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:ServletsReportesPDF.ReporteCortaGranel.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . ja v a2 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; Statement st5 = null; ResultSet rs = null; ResultSet rs2 = null; ResultSet rs3 = null; ResultSet rs4 = null; ResultSet rs5 = 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(); st5 = (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 corta_granel where num_lote ='" + num_lote + "'"); rs3 = st3.executeQuery("SELECT * from corta_granel where num_lote ='" + num_lote + "'"); rs4 = st4.executeQuery("SELECT * from corta_granel where num_lote ='" + num_lote + "'"); rs5 = st5.executeQuery("SELECT * from corta_granel where num_lote ='" + num_lote + "'"); if (con != null) { Document documento = new Document(A4.rotate()); PdfWriter writer = PdfWriter.getInstance(documento, out); FooterPiePaginaiText footer = new FooterPiePaginaiText(); writer.setPageEvent(footer); documento.open(); try { Image imagenes = Image.getInstance( "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png"); imagenes.setAlignment(Element.ALIGN_RIGHT); imagenes.scaleToFit(120, 120); documento.add(imagenes); //documento.add(imagenes); Paragraph par21 = new Paragraph(); Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK); par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip)); par21.setAlignment(Element.ALIGN_CENTER); par21.add(new Phrase(Chunk.NEWLINE)); documento.add(par21); String nombre = null; String Apellido = null; String cedula = null; while (rs.next()) { nombre = (rs.getString("nombre")); cedula = (rs.getString("cedula")); Apellido = (rs.getString("apellido")); } Paragraph par2 = new Paragraph(); Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy "); par2.add(new Paragraph("Fecha: " + dateFormat.format(date), fontfecha)); //par2.add(new Paragraph(new Date().toString())); par2.setAlignment(Element.ALIGN_RIGHT); ; documento.add(par2); Paragraph par7 = new Paragraph(); Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK); par7.add(new Phrase("Nombre: " + nombre + " " + Apellido, fontUsuario)); par7.add(new Phrase("\nc.c: " + cedula, fontUsuario)); par7.setAlignment(Element.ALIGN_LEFT); par7.add(new Phrase(Chunk.NEWLINE)); documento.add(par7); Paragraph par3 = new Paragraph(); Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri)); par3.setAlignment(Element.ALIGN_CENTER); par3.add(new Phrase(Chunk.NEWLINE)); documento.add(par3); } catch (Exception eX) { eX.getMessage(); } try { Paragraph par1 = new Paragraph(); Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase("REPORTE CORTA POR GRANEL", fonttitulo)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); Paragraph par2 = new Paragraph(); Font fonttitulo2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase("REPORTE CORTO DE MAQUINA LLANTA", fonttitulo2)); par2.setAlignment(Element.ALIGN_CENTER); par2.add(new Phrase(Chunk.NEWLINE)); documento.add(par2); PdfPTable tabla = new PdfPTable(4); FontFactory.registerDirectories(); documento.add(new Paragraph("\n")); PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad (Llanta)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Unidad (Llanta)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Total (Llanta)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); tabla.addCell(celda1); tabla.addCell(celda2); tabla.addCell(celda3); tabla.addCell(celda4); while (rs2.next()) { tabla.addCell(rs2.getString("fecha_crg")); tabla.addCell(rs2.getString("cantidad_mq_llanta_crg")); tabla.addCell(rs2.getString("valor_mq_llanta_crg")); tabla.addCell(rs2.getString("valor_total_mq_llanta_crg")); } 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 CORTO DE MAQUINA ORUGA", 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(3); FontFactory.registerDirectories(); PdfPCell celda5 = new PdfPCell(new Paragraph("Cantidad (Oruga)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda6 = new PdfPCell(new Paragraph("Valor Unidad (Oruga)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda7 = new PdfPCell(new Paragraph("Valor Total (Oruga)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda5); tabla2.addCell(celda6); tabla2.addCell(celda7); while (rs3.next()) { tabla2.addCell(rs3.getString("cantidad_mq_oruga_crg")); tabla2.addCell(rs3.getString("valor_mq_oruga_crg")); tabla2.addCell(rs3.getString("valor_total_mq_oruga_crg")); } 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.BLACK); par8.add(new Phrase("REPORTE COSTOS DE FLETE", 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(3); FontFactory.registerDirectories(); PdfPCell celda100 = new PdfPCell(new Paragraph("Cantidad (Flete)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda100.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda110 = new PdfPCell(new Paragraph("Valor Unidad (Flete)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda110.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda120 = new PdfPCell(new Paragraph("Valor Total (Flete)", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda120.setHorizontalAlignment(Element.ALIGN_CENTER); tabla3.addCell(celda100); tabla3.addCell(celda110); tabla3.addCell(celda120); while (rs4.next()) { tabla3.addCell(rs4.getString("cantidad_flete_crg")); tabla3.addCell(rs4.getString("valor_flete_crg")); tabla3.addCell(rs4.getString("valor_total_flete_crg")); } documento.add(tabla3); Paragraph par9 = new Paragraph(); par9.add(new Phrase(Chunk.NEWLINE)); par9.add(new Phrase(Chunk.NEWLINE)); par9.add(new Phrase(Chunk.NEWLINE)); Font fontFooter5 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par9.add(new Phrase("REPORTE COSTOS ADICIONALES", fontFooter5)); par9.setAlignment(Element.ALIGN_CENTER); par9.add(new Phrase(Chunk.NEWLINE)); par9.add(new Phrase(Chunk.NEWLINE)); documento.add(par9); PdfPTable tabla4 = new PdfPTable(4); FontFactory.registerDirectories(); PdfPCell celda150 = new PdfPCell(new Paragraph("Valor Alimentacin", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda150.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda140 = new PdfPCell(new Paragraph("Valor Celadura Mquina", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda140.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda160 = new PdfPCell(new Paragraph("Valor Administracin", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda160.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda170 = new PdfPCell(new Paragraph("Costo Total", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda170.setHorizontalAlignment(Element.ALIGN_CENTER); tabla4.addCell(celda140); tabla4.addCell(celda150); tabla4.addCell(celda160); tabla4.addCell(celda170); while (rs5.next()) { tabla4.addCell(rs5.getString("valor_celaduria_maquina_crg")); tabla4.addCell(rs5.getString("valor_alimentacion_crg")); tabla4.addCell(rs5.getString("valor_administracion_crg")); tabla4.addCell(rs5.getString("valor_total_crg")); } documento.add(tabla4); } catch (Exception e) { e.printStackTrace(); } documento.close(); } } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:ServletsReportesPDF.ReporteCortaMaleza.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w.ja v a 2s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String num_lote = request.getParameter("num_lote"); response.setContentType("application/pdf"); OutputStream out = response.getOutputStream(); try { try { Connection con = null; Statement st = null; Statement st2 = null; Statement st3 = null; ResultSet rs = null; ResultSet rs2 = null; ResultSet rs3 = null; Class.forName("com.mysql.jdbc.Driver"); con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root", "9510"); st = (Statement) con.createStatement(); st2 = (Statement) con.createStatement(); st3 = (Statement) con.createStatement(); rs = st.executeQuery( "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='" + num_lote + "'"); rs2 = st2.executeQuery("SELECT * from manejo_residuos_cosecha where num_lote ='" + num_lote + "'"); rs3 = st3.executeQuery("SELECT * from manejo_residuos_cosecha where num_lote ='" + num_lote + "'"); if (con != null) { Document documento = new Document(A4.rotate()); PdfWriter writer = PdfWriter.getInstance(documento, out); FooterPiePaginaiText footer = new FooterPiePaginaiText(); writer.setPageEvent(footer); documento.open(); try { Image imagenes = Image.getInstance( "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png"); imagenes.setAlignment(Element.ALIGN_RIGHT); imagenes.scaleToFit(120, 120); documento.add(imagenes); //documento.add(imagenes); Paragraph par21 = new Paragraph(); Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK); par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip)); par21.setAlignment(Element.ALIGN_CENTER); par21.add(new Phrase(Chunk.NEWLINE)); documento.add(par21); String nombre = null; String Apellido = null; String cedula = null; while (rs.next()) { nombre = (rs.getString("nombre")); cedula = (rs.getString("cedula")); Apellido = (rs.getString("apellido")); } Paragraph par2 = new Paragraph(); Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy "); par2.add(new Paragraph("Fecha: " + dateFormat.format(date), fontfecha)); //par2.add(new Paragraph(new Date().toString())); par2.setAlignment(Element.ALIGN_RIGHT); ; documento.add(par2); Paragraph par7 = new Paragraph(); Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK); par7.add(new Phrase("Nombre: " + nombre + " " + Apellido, fontUsuario)); par7.add(new Phrase("\nc.c: " + cedula, fontUsuario)); par7.setAlignment(Element.ALIGN_LEFT); par7.add(new Phrase(Chunk.NEWLINE)); documento.add(par7); Paragraph par3 = new Paragraph(); Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri)); par3.setAlignment(Element.ALIGN_CENTER); par3.add(new Phrase(Chunk.NEWLINE)); documento.add(par3); } catch (Exception eX) { eX.getMessage(); } try { Paragraph par1 = new Paragraph(); Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase("REPORTE MANEJO RESIDUOS DE COSECHA", fonttitulo)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); PdfPTable tabla = new PdfPTable(5); FontFactory.registerDirectories(); documento.add(new Paragraph("\n")); PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda2 = new PdfPCell(new Paragraph("Tipo de Manejo", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad Hectreas", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda4 = new PdfPCell(new Paragraph("Valor de Hectreas", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Total", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); tabla.addCell(celda1); tabla.addCell(celda2); tabla.addCell(celda3); tabla.addCell(celda4); tabla.addCell(celda5); while (rs2.next()) { tabla.addCell(rs2.getString("fecha_mrc")); tabla.addCell(rs2.getString("tipo_manejo_mrc")); tabla.addCell(rs2.getString("cantidad_hectareas_mrc")); tabla.addCell(rs2.getString("valor_hectareas_mrc")); tabla.addCell(rs2.getString("valor_total_mrc")); } documento.add(tabla); } catch (Exception e) { e.printStackTrace(); } documento.close(); } } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:ServletsReportesPDF.ReporteDespalille.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w. j 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; ResultSet rs = null; ResultSet rs2 = null; Class.forName("com.mysql.jdbc.Driver"); con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root", "9510"); st = (Statement) con.createStatement(); st2 = (Statement) con.createStatement(); rs = st.executeQuery( "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='" + num_lote + "'"); rs2 = st2.executeQuery("SELECT * from despalille where num_lote ='" + num_lote + "'"); if (con != null) { Document documento = new Document(A4.rotate()); PdfWriter writer = PdfWriter.getInstance(documento, out); FooterPiePaginaiText footer = new FooterPiePaginaiText(); writer.setPageEvent(footer); documento.open(); try { Image imagenes = Image.getInstance( "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png"); imagenes.setAlignment(Element.ALIGN_RIGHT); imagenes.scaleToFit(120, 120); documento.add(imagenes); //documento.add(imagenes); Paragraph par21 = new Paragraph(); Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK); par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip)); par21.setAlignment(Element.ALIGN_CENTER); par21.add(new Phrase(Chunk.NEWLINE)); documento.add(par21); String nombre = null; String Apellido = null; String cedula = null; while (rs.next()) { nombre = (rs.getString("nombre")); cedula = (rs.getString("cedula")); Apellido = (rs.getString("apellido")); } Paragraph par2 = new Paragraph(); Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy "); par2.add(new Paragraph("Fecha: " + dateFormat.format(date), fontfecha)); //par2.add(new Paragraph(new Date().toString())); par2.setAlignment(Element.ALIGN_RIGHT); ; documento.add(par2); Paragraph par7 = new Paragraph(); Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK); par7.add(new Phrase("Nombre: " + nombre + " " + Apellido, fontUsuario)); par7.add(new Phrase("\nc.c: " + cedula, fontUsuario)); par7.setAlignment(Element.ALIGN_LEFT); par7.add(new Phrase(Chunk.NEWLINE)); documento.add(par7); Paragraph par3 = new Paragraph(); Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri)); par3.setAlignment(Element.ALIGN_CENTER); par3.add(new Phrase(Chunk.NEWLINE)); documento.add(par3); } catch (Exception eX) { eX.getMessage(); } try { Paragraph par1 = new Paragraph(); Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase("REPORTE DESPALILLE", fonttitulo)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); PdfPTable tabla = new PdfPTable(4); FontFactory.registerDirectories(); documento.add(new Paragraph("\n")); PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad Jornales", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Unitario Jornal", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Total Jornal", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); tabla.addCell(celda1); tabla.addCell(celda2); tabla.addCell(celda3); tabla.addCell(celda4); while (rs2.next()) { tabla.addCell(rs2.getString("fecha_dsp")); tabla.addCell(rs2.getString("cantidad_mano_obra_dsp")); tabla.addCell(rs2.getString("precio_mano_obra_dsp")); tabla.addCell(rs2.getString("total_mano_obra_dsp")); } documento.add(tabla); } catch (Exception e) { e.printStackTrace(); } documento.close(); } } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:ServletsReportesPDF.ReporteEntresaque.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww . j av a2 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; ResultSet rs = null; ResultSet rs2 = null; Class.forName("com.mysql.jdbc.Driver"); con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root", "9510"); st = (Statement) con.createStatement(); st2 = (Statement) con.createStatement(); rs = st.executeQuery( "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='" + num_lote + "'"); rs2 = st2.executeQuery("SELECT * from entresaque where num_lote ='" + num_lote + "'"); if (con != null) { Document documento = new Document(A4.rotate()); PdfWriter writer = PdfWriter.getInstance(documento, out); FooterPiePaginaiText footer = new FooterPiePaginaiText(); writer.setPageEvent(footer); documento.open(); try { Image imagenes = Image.getInstance( "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png"); imagenes.setAlignment(Element.ALIGN_RIGHT); imagenes.scaleToFit(200, 200); documento.add(imagenes); //documento.add(imagenes); Paragraph par21 = new Paragraph(); Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK); par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip)); par21.setAlignment(Element.ALIGN_CENTER); par21.add(new Phrase(Chunk.NEWLINE)); documento.add(par21); String nombre = null; String Apellido = null; String cedula = null; while (rs.next()) { nombre = (rs.getString("nombre")); cedula = (rs.getString("cedula")); Apellido = (rs.getString("apellido")); } Paragraph par2 = new Paragraph(); Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy "); par2.add(new Paragraph("Fecha: " + dateFormat.format(date), fontfecha)); //par2.add(new Paragraph(new Date().toString())); par2.setAlignment(Element.ALIGN_RIGHT); ; documento.add(par2); Paragraph par7 = new Paragraph(); Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK); par7.add(new Phrase("Nombre: " + nombre + " " + Apellido, fontUsuario)); par7.add(new Phrase("\nc.c: " + cedula, fontUsuario)); par7.setAlignment(Element.ALIGN_LEFT); par7.add(new Phrase(Chunk.NEWLINE)); documento.add(par7); Paragraph par3 = new Paragraph(); Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri)); par3.setAlignment(Element.ALIGN_CENTER); par3.add(new Phrase(Chunk.NEWLINE)); documento.add(par3); } catch (Exception eX) { eX.getMessage(); } try { Paragraph par1 = new Paragraph(); Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase("REPORTE ENTRESAQUE", fonttitulo)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); PdfPTable tabla = new PdfPTable(4); FontFactory.registerDirectories(); documento.add(new Paragraph("\n")); PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda2 = new PdfPCell(new Paragraph("Cantidad Jornales", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda3 = new PdfPCell(new Paragraph("Valor Unitario Jornal", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Total Jornal", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); tabla.addCell(celda1); tabla.addCell(celda2); tabla.addCell(celda3); tabla.addCell(celda4); while (rs2.next()) { tabla.addCell(rs2.getString("fecha_etsq")); tabla.addCell(rs2.getString("cantidad_mano_obra_etsq")); tabla.addCell(rs2.getString("precio_mano_obra_etsq")); tabla.addCell(rs2.getString("total_mano_obra_etsq")); } documento.add(tabla); } catch (Exception e) { e.printStackTrace(); } documento.close(); } } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }
From source file:ServletsReportesPDF.ReporteFumigas.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w. j av a 2 s .co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String num_lote = request.getParameter("num_lote"); response.setContentType("application/pdf"); OutputStream out = response.getOutputStream(); try { try { Connection con = null; Statement st = null; Statement st2 = null; Statement st3 = null; ResultSet rs = null; ResultSet rs2 = null; ResultSet rs3 = null; Class.forName("com.mysql.jdbc.Driver"); con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/simpca", "root", "9510"); st = (Statement) con.createStatement(); st2 = (Statement) con.createStatement(); st3 = (Statement) con.createStatement(); rs = st.executeQuery( "SELECT usuario.cedula,nombre,apellido,telefono FROM usuario JOIN lote ON lote.usuario_cedula=usuario.cedula WHERE lote.num_lote='" + num_lote + "'"); rs2 = st2.executeQuery("SELECT * from fumiga where num_lote ='" + num_lote + "'"); rs3 = st3.executeQuery( "SELECT * from fumiga f JOIN insumos_fumiga i on i.id_fumiga = f.id_fumiga where f.num_lote ='" + num_lote + "'"); if (con != null) { Document documento = new Document(A4.rotate()); PdfWriter writer = PdfWriter.getInstance(documento, out); FooterPiePaginaiText footer = new FooterPiePaginaiText(); writer.setPageEvent(footer); documento.open(); try { Image imagenes = Image.getInstance( "C:\\Users\\USUARIO\\Desktop\\simpca\\SIMPCA Coagronorte\\web\\ImagenesR\\coagronorte-slogan.png"); imagenes.setAlignment(Element.ALIGN_RIGHT); imagenes.scaleToFit(200, 200); documento.add(imagenes); //documento.add(imagenes); Paragraph par21 = new Paragraph(); Font fontDescrip = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.ITALIC, BaseColor.BLACK); par21.add(new Phrase("Cooperativa Agropecuaria de Norte de Santander", fontDescrip)); par21.setAlignment(Element.ALIGN_CENTER); par21.add(new Phrase(Chunk.NEWLINE)); documento.add(par21); String nombre = null; String Apellido = null; String cedula = null; while (rs.next()) { nombre = (rs.getString("nombre")); cedula = (rs.getString("cedula")); Apellido = (rs.getString("apellido")); } Paragraph par2 = new Paragraph(); Font fontfecha = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL, BaseColor.BLACK); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy "); par2.add(new Paragraph("Fecha: " + dateFormat.format(date), fontfecha)); //par2.add(new Paragraph(new Date().toString())); par2.setAlignment(Element.ALIGN_RIGHT); ; documento.add(par2); Paragraph par7 = new Paragraph(); Font fontUsuario = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLACK); par7.add(new Phrase("Nombre: " + nombre + " " + Apellido, fontUsuario)); par7.add(new Phrase("\nc.c: " + cedula, fontUsuario)); par7.setAlignment(Element.ALIGN_LEFT); par7.add(new Phrase(Chunk.NEWLINE)); documento.add(par7); Paragraph par3 = new Paragraph(); Font fontDescri = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); par3.add(new Phrase("Numero Lote:\n " + num_lote, fontDescri)); par3.setAlignment(Element.ALIGN_CENTER); par3.add(new Phrase(Chunk.NEWLINE)); documento.add(par3); } catch (Exception eX) { eX.getMessage(); } try { Paragraph par1 = new Paragraph(); Font fonttitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase("REPORTE FUMIGAS", fonttitulo)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); PdfPTable tabla = new PdfPTable(6); FontFactory.registerDirectories(); documento.add(new Paragraph("\n")); PdfPCell celda1 = new PdfPCell(new Paragraph("Fecha", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda2 = new PdfPCell(new Paragraph("Tipo de Fumiga", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda3 = new PdfPCell(new Paragraph("Cantidad Jornales", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda4 = new PdfPCell(new Paragraph("Valor Jornal", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda5 = new PdfPCell(new Paragraph("Valor Total Mano Obra", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); PdfPCell celda6 = new PdfPCell(new Paragraph("Valor Total Fumiga", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); tabla.addCell(celda1); tabla.addCell(celda2); tabla.addCell(celda3); tabla.addCell(celda4); tabla.addCell(celda5); tabla.addCell(celda6); while (rs2.next()) { tabla.addCell(rs2.getString("fecha_fumiga")); tabla.addCell(rs2.getString("nombre_fumiga_fumiga")); tabla.addCell(rs2.getString("cantidad_mano_obra_fumiga")); tabla.addCell(rs2.getString("valor_uni_mano_obra_fumiga")); tabla.addCell(rs2.getString("valor_total_mano_obra_fumiga")); tabla.addCell(rs2.getString("valor_total_fumiga")); } documento.add(tabla); Paragraph par4 = new Paragraph(); par4.add(new Phrase(Chunk.NEWLINE)); par4.add(new Phrase(Chunk.NEWLINE)); par4.add(new Phrase(Chunk.NEWLINE)); Font fontFooter2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK); par4.add(new Phrase("REPORTE INSUMOS FUMIGAS", fontFooter2)); par4.setAlignment(Element.ALIGN_CENTER); par4.add(new Phrase(Chunk.NEWLINE)); par4.add(new Phrase(Chunk.NEWLINE)); documento.add(par4); PdfPTable tabla2 = new PdfPTable(6); FontFactory.registerDirectories(); PdfPCell celda10 = new PdfPCell(new Paragraph("Tipo", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda10.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda20 = new PdfPCell(new Paragraph("Nombre", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda20.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda30 = new PdfPCell(new Paragraph("Cantidad", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda30.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda40 = new PdfPCell(new Paragraph("Unidad", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda40.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda50 = new PdfPCell(new Paragraph("Valor Unitario", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda50.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell celda60 = new PdfPCell(new Paragraph("Valor Total", FontFactory.getFont("Times New Roman", 12, Font.BOLD, BaseColor.BLACK))); celda60.setHorizontalAlignment(Element.ALIGN_CENTER); tabla2.addCell(celda10); tabla2.addCell(celda20); tabla2.addCell(celda30); tabla2.addCell(celda40); tabla2.addCell(celda50); tabla2.addCell(celda60); while (rs3.next()) { tabla2.addCell(rs3.getString("tipo_insumo")); tabla2.addCell(rs3.getString("nombre_insumo")); tabla2.addCell(rs3.getString("cantidad_insumo")); tabla2.addCell(rs3.getString("unidad_insumo")); tabla2.addCell(rs3.getString("valor_unitario_insumo")); tabla2.addCell(rs3.getString("valor_total_insumos")); } documento.add(tabla2); } catch (Exception e) { e.printStackTrace(); } documento.close(); } } catch (Exception e) { e.getMessage(); } } finally { out.close(); } }