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:Servicios.SmLogistics.java
private void b_pago_formatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_pago_formatoActionPerformed // TODO add your handling code here: Session session = HibernateUtil.getSessionFactory().openSession(); try {/*ww w. j ava 2 s . c o m*/ Orden ord = (Orden) session.get(Orden.class, orden_act.getIdOrden()); Configuracion con = (Configuracion) session.get(Configuracion.class, 1); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); String formato = "PagoAXA.pdf";//ord.getCompania().getFormatoPago(); File folder = new File("reportes/" + ord.getIdOrden()); folder.mkdirs(); PdfReader reader = new PdfReader("imagenes/" + formato); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-Pago.pdf")); PdfContentByte cb = stamp.getUnderContent(1); AcroFields fdfDoc = stamp.getAcroFields(); cb.beginText(); //IMAGEN try { Image img = Image.getInstance("imagenes/" + con.getLogo()); img.setAbsolutePosition(25, 710); img.scaleAbsoluteWidth(75); img.scaleAbsoluteHeight(50); cb.addImage(img, true); } catch (Exception e) { e.printStackTrace(); } try { Image img_1 = Image.getInstance(ord.getCompania().getFoto()); img_1.setAbsolutePosition(500, 735); img_1.scaleAbsoluteWidth(80); img_1.scaleAbsoluteHeight(50); cb.addImage(img_1, true); } catch (Exception e) { e.printStackTrace(); } Foto foto = (Foto) session.createCriteria(Foto.class) .add(Restrictions.eq("orden.idOrden", orden_act.getIdOrden())).addOrder(Order.desc("fecha")) .setMaxResults(1).uniqueResult(); if (foto != null) { try { Image img_2 = Image .getInstance("ordenes/" + ord.getIdOrden() + "/miniatura/" + foto.getDescripcion()); img_2.setAbsolutePosition(480, 558); img_2.scaleAbsoluteWidth(90); img_2.scaleAbsoluteHeight(50); cb.addImage(img_2, true); } catch (Exception e) { } } //NOMBRE DEL TALLER if (con.getEmpresa() != null) fdfDoc.setField("NombreEmpresa", con.getEmpresa()); //DIRECCION DEL TALLER String direccion = ""; if (con.getDireccion() != null) direccion += con.getDireccion() + " "; if (con.getNo() != null) direccion += con.getNo() + " "; if (con.getColonia() != null) direccion += con.getColonia(); direccion = direccion.toUpperCase(); fdfDoc.setField("DireccionEmpresa", direccion); //Municipio, Estado, CP String municipio = ""; if (con.getMunicipio() != null) municipio += con.getMunicipio() + " "; if (con.getEstado() != null) municipio += con.getEstado() + " "; if (con.getCp() != null) municipio += con.getCp(); municipio = municipio.toUpperCase(); fdfDoc.setField("ColoniaEmpresa", municipio); //Pagina Web y Telefonos fdfDoc.setField("SitioEmpresa", "tracto.ddns.net"); fdfDoc.setField("TelefonoEmpresa", "(722) 199 24 04 / 275 19 45"); //Datos de la compaia fdfDoc.setField("Aseguradora1", ord.getCompania().getSocial()); if (ord.getCompania().getDireccion() != null) fdfDoc.setField("Aseguradora2", ord.getCompania().getDireccion()); if (ord.getCompania().getColonia() != null) fdfDoc.setField("Aseguradora3", ord.getCompania().getColonia()); /*if(ord.getCompania().getComentarios()!=null) fdfDoc.setField("Extra", ord.getCompania().getComentarios());*/ //Orden de trabajo fdfDoc.setField("Orden", "" + ord.getIdOrden()); //FECHA INGRESO if (ord.getFecha() != null) fdfDoc.setField("FechaRecepcion", ord.getFecha().toString()); //Marca fdfDoc.setField("Marca", ord.getMarca().getMarcaNombre()); //Tipo fdfDoc.setField("Modelo", "" + ord.getTipo().getTipoNombre()); //Placas if (ord.getNoPlacas() != null) fdfDoc.setField("Placas", "" + ord.getNoPlacas()); //Poliza if (ord.getPoliza() != null) fdfDoc.setField("Poliza", "" + ord.getPoliza()); //Siniestro if (ord.getSiniestro() != null) fdfDoc.setField("Siniestro", "" + ord.getSiniestro()); //Datos cliente if (ord.getClientes() != null) { fdfDoc.setField("Nombre", ord.getClientes().getNombre()); if (ord.getClientes().getContacto() != null) fdfDoc.setField("Contacto", ord.getClientes().getContacto()); } //Datos de atencion a clientes fdfDoc.setField("Tel1", "722 299 240 25"); fdfDoc.setField("Id1", "52*167862*13"); fdfDoc.setField("Email1", "atencionaclientes@tractoservicio.com"); fdfDoc.setField("Wat1", "722 299 240 25"); float tam[] = new float[] { 160, 80, 130, 170 }; Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD); PDF reporte = new PDF(); PdfPTable tabla = reporte.crearTabla(4, tam, 100, Element.ALIGN_LEFT); tabla.setTotalWidth(tam); BaseColor cabecera = BaseColor.GRAY; BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; if (formato.compareToIgnoreCase("PagoAXA.pdf") != 0) { tabla.addCell(reporte.celda("BANCO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("NO CONVENIO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("N DE CUENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell( reporte.celda("NOMBRE DE LA COMPAIA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE)); Cuenta[] cuentas = (Cuenta[]) ord.getCompania().getCuentas().toArray(new Cuenta[0]); if (cuentas.length > 0) { for (int i = 0; i < cuentas.length; i++) { tabla.addCell(reporte.celda(cuentas[i].getBanco(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(cuentas[i].getConvenio().toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(cuentas[i].getTransferencia(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(cuentas[i].getNombre(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } } tabla.completeRow(); tabla.writeSelectedRows(0, -1, 40, 420, cb); } DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); cb.setTextMatrix(160, 466); BaseFont bf = BaseFont.createFont(); cb.setFontAndSize(bf, 9); cb.showText("" + formatoPorcentaje.format(orden_act.getDeducible())); cb.setTextMatrix(450, 466); cb.showText("" + formatoPorcentaje.format(orden_act.getDemerito())); cb.endText(); stamp.close(); reporte.cerrar(); reporte.visualizar2("reportes/" + ord.getIdOrden() + "/" + valor + "-Pago.pdf"); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } if (session != null) if (session.isOpen()) session.close(); }
From source file:Servlets.PDF.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); Document document = new Document(PageSize.A4, 50, 50, 50, 50); try {//from ww w . j a v a2 s . com //obtengo datos de cliente, reserva y total String rreserva = request.getParameter("reserva"); String rcliente = request.getParameter("cliente"); String rtotal = request.getParameter("total"); //String rtipo = request.getParameter("esProv"); // Obtener datos de cliente e items de reserva DtUsuario dtu = getDtUsuario(rcliente); String nombre = dtu.getNombre(); String apellido = dtu.getApellido(); String servicios = ""; String promos = ""; java.util.List<DtItemReserva> dtItems = listarItems(Integer.parseInt(rreserva)).getItems(); Iterator<DtItemReserva> iter = dtItems.iterator(); DtItemReserva dtItem; // Crear y abrir documento String HomeDeUSuario = System.getProperty("user.home"); String ruta = HomeDeUSuario + "/Factura Reserva " + rreserva + ".pdf"; FileOutputStream archivo = new FileOutputStream(ruta); PdfWriter writer = PdfWriter.getInstance(document, archivo); document.open(); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); String fecha = dateFormat.format(date); // Agregar marcador inicial // Crear y agregar prrafo simple Paragraph paragraph1 = new Paragraph(); Image imagen = Image.getInstance("http://localhost:8084/Help4TravelingWeb/img/logo-icon2.png"); imagen.scaleAbsolute(200f, 200f); imagen.setAbsolutePosition(10, 650); imagen.setSpacingAfter(20); paragraph1.add(imagen); document.add(paragraph1); //fecha Paragraph fecha1 = new Paragraph(fecha); //encabezado Paragraph futuros = new Paragraph("Futuros Tecnologos SRL"); Paragraph rut = new Paragraph("RUT 123456789012"); Paragraph direccion = new Paragraph(" Av. Gral. Rivera 3629"); Paragraph telefono = new Paragraph(" Tel: 555-5412"); Paragraph nombre_empresa = new Paragraph(" Help4Travelling"); //datos cliente String nombrecliente = nombre.toUpperCase() + " " + apellido.toUpperCase(); String direccioncliente = " "; String rutcliente = "consumidor final".toUpperCase(); Paragraph cliente = new Paragraph("Cliente: " + nombrecliente); Paragraph dircliente = new Paragraph("Direccion: " + direccioncliente); Paragraph rutcli = new Paragraph("RUT: " + rutcliente); //datos boleta String factura = rreserva; Paragraph tipodoc = new Paragraph("Contado"); Paragraph Nfac = new Paragraph(" N " + factura); //alineaciones //fecha fecha1.setAlignment(Element.ALIGN_RIGHT); //encabezado futuros.setAlignment(Element.ALIGN_CENTER); rut.setAlignment(Element.ALIGN_CENTER); direccion.setAlignment(Element.ALIGN_CENTER); telefono.setAlignment(Element.ALIGN_CENTER); //nombre empresa nombre_empresa.setAlignment(Element.ALIGN_LEFT); nombre_empresa.setSpacingBefore(10); nombre_empresa.setSpacingAfter(30); //datos de boleta tipodoc.setAlignment(Element.ALIGN_RIGHT); Nfac.setAlignment(Element.ALIGN_RIGHT); document.add(fecha1); document.add(futuros); document.add(rut); document.add(direccion); document.add(telefono); document.add(nombre_empresa); document.add(tipodoc); document.add(Nfac); document.add(cliente); document.add(dircliente); document.add(rutcli); PdfPTable tabla = new PdfPTable(4); tabla.setSpacingBefore(25); tabla.setSpacingAfter(25); //creo encabezado de tabla PdfPCell codigo = new PdfPCell(new Phrase("Proveedor".toUpperCase())); PdfPCell descripcion = new PdfPCell(new Phrase("descripcion".toUpperCase())); PdfPCell ecantidad = new PdfPCell(new Phrase("cantidad".toUpperCase())); PdfPCell eprecio = new PdfPCell(new Phrase("precio".toUpperCase())); tabla.setHeaderRows(1); tabla.setWidthPercentage(100f); //alineamos las frases del cabezal codigo.setHorizontalAlignment(Element.ALIGN_CENTER); descripcion.setHorizontalAlignment(Element.ALIGN_CENTER); ecantidad.setHorizontalAlignment(Element.ALIGN_CENTER); eprecio.setHorizontalAlignment(Element.ALIGN_CENTER); //agrego cabezal de tabla tabla.addCell(codigo); tabla.addCell(descripcion); tabla.addCell(ecantidad); tabla.addCell(eprecio); //obtengo datos de la reserva para imprimir las distintas rows while (iter.hasNext()) { dtItem = iter.next(); Integer cantidad = dtItem.getCantidad(); String oferta = dtItem.getOferta().getNombre(); String precio; String proveedor; if (existeServicio(oferta)) { proveedor = getNkProveedorServicio(oferta); DtServicio dts = getDtServicio(oferta, proveedor); precio = String.valueOf(dts.getPrecio()); } else { proveedor = getNkProveedorPromocion(oferta); DtPromocion dtp = getDTPromocion(oferta, proveedor); precio = dtp.getDescuento(); } /* String item = "<li>Nombre: <em>" + oferta + "</em>" + " - Cantidad: <em>" + cantidad + "</em>" + " - $:<em>" + precio + "</em>" + " - Proveedor: <em>" + proveedor + "</em></li>";*/ //creo encabezado de tabla PdfPCell iproveedor = new PdfPCell(new Phrase(proveedor.toUpperCase())); PdfPCell icantidad = new PdfPCell(new Phrase(cantidad.toString())); PdfPCell iprecio = new PdfPCell(new Phrase(precio.toUpperCase())); tabla.setHeaderRows(1); //alineamos las frases del cabezal iproveedor.setHorizontalAlignment(Element.ALIGN_CENTER); icantidad.setHorizontalAlignment(Element.ALIGN_CENTER); iprecio.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(iproveedor); if (existeServicio(oferta)) { PdfPCell idescripcion = new PdfPCell(new Phrase("servicio: " + oferta)); idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(idescripcion); } else { PdfPCell idescripcion = new PdfPCell(new Phrase("Promo: " + oferta)); idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(idescripcion); } tabla.addCell(icantidad); tabla.addCell(iprecio); } /* // las distintas rows de los articulos tabla.addCell(proveedor); tabla.addCell(oferta); tabla.addCell(cantidad); tabla.addCell(precio); */ //el ulimo de la tabla que da el total PdfPCell celdaFinal = new PdfPCell(new Paragraph("")); PdfPCell celdaTotal = new PdfPCell(new Paragraph("total:")); PdfPCell celdaPrecioTotal = new PdfPCell(new Paragraph(rtotal)); // Indicamos cuantas columnas ocupa la celda celdaFinal.setColspan(2); celdaTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); celdaPrecioTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celdaFinal); tabla.addCell(celdaTotal); tabla.addCell(celdaPrecioTotal); document.add(tabla); document.close(); if (request.getParameter("dispositivo").equals("true")) response.sendRedirect("Movil.Reservas.jsp"); else response.sendRedirect("Usuario.jsp"); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:servlets.POPDF.java
private void buildpdf(PurchaseOrderDTO dto, HttpServletResponse response) { Font catFont = new Font(Font.FontFamily.HELVETICA, 24, Font.BOLD); Font subFont = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD); Font smallBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); String IMG = getServletContext().getRealPath("/img/logo.png"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(); VendorDTO venDTO = venModel.getVendor(dto.getVendorno(), ds); DecimalFormat decimal = new DecimalFormat("#0.00"); ArrayList<ProductDTO> products = prodModel.getProdsForVendor(dto.getVendorno(), ds); ArrayList<POLineItemDTO> poLineItems = dto.getItems(); try {//from w ww . ja v a2 s .c o m PdfWriter.getInstance(document, baos); document.open(); Paragraph preface = new Paragraph(); // We add one empty line Image image1 = Image.getInstance(IMG); image1.setAbsolutePosition(55f, 760f); preface.add(image1); preface.setAlignment(Element.ALIGN_RIGHT); // Lets write a big header Paragraph mainHead = new Paragraph(String.format("%55s", "Purchase Order"), catFont); preface.add(mainHead); preface.setAlignment(Element.ALIGN_LEFT); preface.add(new Paragraph(String.format("%82s", "PO#: " + dto.getPONumber()), subFont)); addEmptyLine(preface, 3); preface.add(new Paragraph(String.format("%10s", "Vendor: ", smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getName(), smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getAddress1(), smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getCity(), smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getProvince(), smallBold))); preface.add(new Paragraph(String.format("%5s", venDTO.getPostalCode(), smallBold))); addEmptyLine(preface, 1); // 3 column table PdfPTable table = new PdfPTable(5); PdfPCell cell = new PdfPCell(new Paragraph("Product Code", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Paragraph("Product Description", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Paragraph("Quantity Sold", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Paragraph("Price", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Paragraph("Ext Price", smallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); for (POLineItemDTO item : poLineItems) { cell = new PdfPCell(new Phrase(item.getproductcode())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); for (ProductDTO prod : products) { if (prod.getProductcode().equals(item.getproductcode())) { cell = new PdfPCell(new Phrase(prod.getProductname())); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } } cell = new PdfPCell(new Phrase(Integer.toString(item.getQuantity()))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); double extPrice = 0.0; for (ProductDTO prod : products) { if (prod.getProductcode().equals(item.getproductcode())) { cell = new PdfPCell(new Phrase(Double.toString(prod.getCostprice()))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); extPrice = prod.getCostprice() * item.getQuantity(); } } String extPriceStr = decimal.format(extPrice); cell = new PdfPCell(new Phrase(extPriceStr)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } //end for double sub = dto.getAmount(); double tax = dto.getAmount() * 0.13; double total = dto.getAmount() * 1.13; String taxStr = decimal.format(tax); String totalStr = decimal.format(total); String subStr = decimal.format(sub); cell = new PdfPCell(new Phrase("Total:")); cell.setColspan(4); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell = new PdfPCell(new Phrase(subStr)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell = new PdfPCell(new Phrase("Tax:")); cell.setColspan(4); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell = new PdfPCell(new Phrase(taxStr)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell = new PdfPCell(new Phrase("Order Total:")); cell.setColspan(4); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell = new PdfPCell(new Phrase(totalStr)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBackgroundColor(BaseColor.YELLOW); table.addCell(cell); preface.add(table); addEmptyLine(preface, 3); preface.setAlignment(Element.ALIGN_CENTER); preface.add(new Paragraph(String.format("%60s", "Generated on: " + dto.getPODate()), subFont)); document.add(preface); document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); // the contentlength response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (Exception e) { System.out.println("Error " + e.getMessage()); } }
From source file:Servlets.ReportsServlet.java
public PdfPTable reports(String lotnum, String reportName, float cSize) { //specify column widths float[] columnWidths = { .12f, .14f, .18f, .25f, .08f, .1f, .1f, .1f, .15f, cSize }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); //PdfPTable table = new PdfPTable(10); // set table width a percentage of the page width table.setWidthPercentage(100f);//from w w w.j a v a 2 s .c o m switch (reportName) { case "IT Report": try { /* IT REPORT GENERATION BLOCK */ //insert column headings insertCell(table, "IT GP No", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "TR No and IT Date", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farmer's Name\n and ID", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Ref No.\n (New and Old)", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Size", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Trees Cut ", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Expected Trees ", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Treated Area", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "IT Grant Payable", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Remarks", Element.ALIGN_CENTER, 1, bfBold8); table.setHeaderRows(1); ResultSet rs = manager.PDFdemos(lotnum); float totalFarmsSize = 0; int totalTreesCut = 0; int totalExpectedTrees = 0; float totalTreatedArea = 0; float totalITGrantPayabe = 0; //Populating Feilds while (rs.next()) { insertCell(table, rs.getString(7), Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, rs.getString(8), rs.getDate(9) + "", Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getString(5), rs.getString(6), Element.ALIGN_LEFT, 1, bfBold8small, bf8); insertCell(table, rs.getString(1), rs.getString(11), Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, String.format("%.2f", rs.getFloat(2)) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getInt(3) + "", Element.ALIGN_LEFT, 1, bf8); int itExpectedTrees = (int) (rs.getFloat(4) * 1100); insertCell(table, itExpectedTrees + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, String.format("%.2f", rs.getFloat(4)) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, String.format("%.2f", rs.getFloat(10)) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, " ", Element.ALIGN_RIGHT, 1, bf8); totalFarmsSize = totalFarmsSize + rs.getFloat(2); totalTreesCut = totalTreesCut + rs.getInt(3); totalExpectedTrees = totalExpectedTrees + itExpectedTrees; totalTreatedArea = totalTreatedArea + rs.getFloat(4); totalITGrantPayabe = totalITGrantPayabe + rs.getFloat(10); } insertCell(table, manager.totalFarms(lotnum) + " treated farms Totals", Element.ALIGN_RIGHT, 4, bfBold8); insertCell(table, String.format("%.2f", totalFarmsSize) + "", Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, totalTreesCut + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, totalExpectedTrees + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, String.format("%.2f", totalTreatedArea) + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, String.format("%.2f", totalITGrantPayabe) + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, " ", Element.ALIGN_CENTER, 1, bfBold8); } //Try ends here catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } break; case "TR Report": try { /* TR REPORT GENERATION BLOCK */ //insert column headings insertCell(table, "IT GP No", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "TR No and IT Date", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farmer's Name", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Ref No.\n (New and Old)", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Size", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Trees Cut ", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Expected Trees ", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "Estimated Trees", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "Treated Area", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "TR Payable", Element.ALIGN_CENTER, 1, bfBold8small); table.setHeaderRows(1); ResultSet rs = manager.TRReportPDF(lotnum); float totalFarmsSize = 0; int totalTreesCut = 0; int totalExpectedTrees = 0; float totalTreatedArea = 0; float totalITGrantPayabe = 0; int totalEstimated = 0; //Populating Feilds while (rs.next()) { insertCell(table, rs.getString(7), Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(8), rs.getDate(9) + "", Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getString(6), Element.ALIGN_LEFT, 1, bfBold8small); insertCell(table, rs.getString(1), rs.getString(11), Element.ALIGN_LEFT, 1, bfBold8small, bf8); insertCell(table, String.format("%.2f", rs.getFloat(2)) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getInt(3) + "", Element.ALIGN_LEFT, 1, bf8); int trExpected = (int) (rs.getFloat(4) * 1100); insertCell(table, trExpected + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getInt(5) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, String.format("%.2f", rs.getFloat(4)) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, String.format("%.2f", rs.getFloat(10)) + "", Element.ALIGN_RIGHT, 1, bf8); totalFarmsSize += rs.getFloat(2); totalTreesCut += rs.getInt(3); totalExpectedTrees += trExpected; totalEstimated += rs.getInt(5); totalTreatedArea += rs.getFloat(4); totalITGrantPayabe += rs.getFloat(10); } insertCell(table, manager.totalFarms(lotnum) + " treated farms Totals", Element.ALIGN_RIGHT, 4, bfBold8); insertCell(table, String.format("%.2f", totalFarmsSize) + "", Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, totalTreesCut + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, totalExpectedTrees + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, totalEstimated + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, totalTreatedArea + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, String.format("%.2f", totalITGrantPayabe) + "", Element.ALIGN_CENTER, 1, bfBold8small); } //Try ends here catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } break; case "RP Report": break; case "Rehab Report": break; default: break; //Switch ends here } return table; }
From source file:Servlets.ReportsServlet.java
public PdfPTable reports(String rehLot) { //specify column widths float[] columnWidths = { .2f, .18f, .2f, .4f, .3f, .2f, .2f, .2f, .2f, .15f, .2f }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); //PdfPTable table = new PdfPTable(10); // set table width a percentage of the page width table.setWidthPercentage(100f);/*from www.j ava 2s .com*/ try { //insert column headings insertCell(table, "TR Voucher No", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "TR Date", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Farmer's Name", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Farm number", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Contractor ", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Farmer's Size", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Cocoa Condition", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Treated Area", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "No of Trees Cut", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Exp Trees", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "TR Payable", Element.ALIGN_LEFT, 1, bfBold8); table.setHeaderRows(1); //Merge cells to input title ie. Region names // insertCell(table, "Bawdua", Element.ALIGN_CENTER, 10, bfBold12); ResultSet rs = manager.PDFRehab(rehLot); float totalFarmSizeReh = 0; float totalTreatedAreaReh = 0; float totalTRpayableReh = 0; int totalExpectedTreesReh = 0; int totalNumberOfTrees = 0; while (rs.next()) { try { insertCell(table, rs.getString(6), Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(18), Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(4) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(1), rs.getString(13), Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getString(15), Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getFloat(7) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getString(17), rs.getString(16), Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getFloat(8) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getInt(11) + "", Element.ALIGN_LEFT, 1, bf8); int Rehab_trExpected = (int) (rs.getFloat(7) * 1100); insertCell(table, Rehab_trExpected + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getFloat(20) + "", Element.ALIGN_LEFT, 1, bf8); totalFarmSizeReh += rs.getFloat(7); totalTRpayableReh += rs.getFloat(20); totalTreatedAreaReh += rs.getFloat(8); totalNumberOfTrees += rs.getInt(11); totalExpectedTreesReh += Rehab_trExpected; } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } } insertCell(table, "Total Farms in the Region " + manager.allRehabFarms(rehLot), Element.ALIGN_LEFT, 4, bfBold8); // insertCell(table, rs.getString(18), Element.ALIGN_LEFT, 1, bf8); // insertCell(table, rs.getString(4) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, "TOTALS", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, String.format("%.2f", totalFarmSizeReh), Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, " ", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, String.format("%.2f", totalTreatedAreaReh), Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, totalNumberOfTrees + "", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "" + totalExpectedTreesReh, Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, String.format("%.2f", totalTRpayableReh), Element.ALIGN_LEFT, 1, bfBold8); //Merge cells for Contractor area // insertCell(table, "Details of Tree Removal in favour of Contractor: " // + "Omenaaba Company Limited", Element.ALIGN_LEFT, 6, bfBold8); // // //Dummy data // insertCell(table, "10010", Element.ALIGN_RIGHT, 1, bf8); // insertCell(table, "ABC00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // // //Merge cells for District Total // insertCell(table, "District Total", Element.ALIGN_LEFT, 4, bfBold8); // // //Dummy data // insertCell(table, "10010", Element.ALIGN_RIGHT, 1, bf8); // insertCell(table, " ", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // // //Merge cells for Region Total // insertCell(table, "Region Total", Element.ALIGN_LEFT, 4, bfBold8); // // //Dummy data // insertCell(table, "10010", Element.ALIGN_RIGHT, 1, bf8); // insertCell(table, " ", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } return table; }
From source file:Servlets.ReportsServlet.java
public PdfPTable RPreport(String lotnum) { //specify column widths float[] columnWidths = { .18f, .18f, .25f, .27f, .1f, .1f, .12f, .1f, .15f, .1f, .1f, .1f, .1f, .1f, .1f, .1f, .15f };//from w w w . j a va2 s. c o m //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); //PdfPTable table = new PdfPTable(10); // set table width a percentage of the page width table.setWidthPercentage(100f); try { /* Replanting REPORT GENERATION BLOCK */ //insert column headings insertCell(table, "RP GP No\nand RP Date", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "IT No \nand IT Date", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farmer's Name\n and ID", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Ref No.\n (New and Old)", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Size", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Treated Area ", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "IT Grant Paid", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "Area Repl", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { 3f, .1f, .1f, .1f }); insertCell(table, "Gross RP", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Seeds\nQty Prev Purch", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Seeds\nQty Supl Free", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Fert\nQty Alloc(Bags)", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Fert\nQty Purch", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Deduc's\nCost of Seed", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Deduc's\nCost of Fert Alloc", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Deduc's\nTotal Deduct", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Net RP Payable", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, 3f, .1f, .1f }); table.setHeaderRows(1); ResultSet rs = manager.PDFreplants(lotnum); float totalFsize = 0; float totalTarea = 0; float totalITPay = 0; float totalAreaRpl = 0; float totalGross = 0; int totalQpp = 0; int totalQsp = 0; int totalQsf = 0; int totalQalloc = 0; int totalQpurchase = 0; float totalCostSeed = 0; float totalCostFert = 0; float totalDeduct = 0; float totalNet = 0; //Populating Feilds while (rs.next()) { insertCell(table, rs.getString(10), rs.getString(11), Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getString(7) + "\n" + rs.getString(8), Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(5), rs.getString(6), Element.ALIGN_LEFT, 1, bfBold8small, bf8); insertCell(table, rs.getString(1), rs.getString(2), Element.ALIGN_LEFT, 1, bfBold8small, bf8); insertCell(table, rs.getFloat(3) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getFloat(4) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(9) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(12) + "", Element.ALIGN_CENTER, 1, bf8, borderA = new float[] { 3f, .1f, .1f, .1f }); insertCell(table, rs.getFloat(15) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getInt(19) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getInt(13) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getInt(20) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getInt(18) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(21) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(14) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(16) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(17) + "", Element.ALIGN_CENTER, 1, bf8, borderB = new float[] { .1f, 3f, .1f, .1f }); totalFsize = totalFsize + rs.getFloat(3); totalTarea = totalTarea + rs.getFloat(4); totalITPay = totalITPay + rs.getFloat(9); totalAreaRpl = totalAreaRpl + rs.getFloat(12); totalGross = totalGross + rs.getFloat(15); totalQpp = totalQpp + rs.getInt(19); totalQsf = totalQsf + rs.getInt(13); totalQalloc = totalQalloc + rs.getInt(14); totalQpurchase = totalQpurchase + rs.getInt(18); totalCostSeed = totalCostSeed + rs.getFloat(21); totalCostFert = totalCostFert + rs.getFloat(20); totalDeduct = totalDeduct + rs.getFloat(16); totalNet = totalNet + rs.getFloat(17); } //Totals insertCell(table, manager.totalFarmsReplant(lotnum) + " Replanted Farms Totals", Element.ALIGN_RIGHT, 4, bfBold8); insertCell(table, String.format("%.2f", totalFsize) + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, String.format("%.2f", totalTarea) + "", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, String.format("%.2f", totalITPay) + "", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, String.format("%.2f", totalAreaRpl) + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { 3f, .1f, .1f, .1f }); insertCell(table, String.format("%.2f", totalGross) + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalQpp + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalQsf + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalCostFert + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalQpurchase + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalCostSeed + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalQalloc + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalDeduct + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, String.format("%.2f", totalNet) + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, 3f, 3f, .1f }); } //Try ends here catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } return table; }
From source file:Servlets.ReportsServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . ja va2 s .com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Paragraph pp; Paragraph palaglapgh, signParagraph, dateParagrapgh; Chunk chk; Paragraph underText; Chunk chuk1; Chunk chuk2; Paragraph regionText; String x; ResultSet dir; Paragraph regionTexts; String repLot; repLot = request.getParameter("report"); String repNum = request.getParameter("ITLot"); Paragraph newDate; response.setContentType("application/pdf"); OutputStream out = response.getOutputStream(); //Create document for pdf Document doc = new Document(); //PDF writer to write into document PdfWriter docwriter = null; DecimalFormat df = new DecimalFormat("0.00"); switch (repLot) { default: break; case "IT Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(20f, 20f, 10f, 10f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .25f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "TR Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); //doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); // 0.1 thickness and -2 position chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .1f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "RP Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFreplants(repNum); try { if (dir.next()) { x = dir.getString(22); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(RPreport(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "Rehab Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(5f, 5f, 3f, 3f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("Component 1 Rehabilitation Tree Removal Cost From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", bfBold12); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum, bfBold12); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFRehab(repNum);//SHOULD BE CHANGED!!!! try { if (dir.next()) { x = dir.getString(21); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); //Copied CODES break; } } catch (DocumentException ex) { Logger.getLogger(ReportsServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ServletsReportesPDF.ReporteAbonadas.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . j a v a2s. 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 { 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./*from www. j a 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; 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./* w ww. j a 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; 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(); } }