List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage
public void setWidthPercentage(final float widthPercentage)
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 w ww .j a v a2 s . c o m //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.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); switch (reportName) { case "IT Report": try {/* w w w . j a v a 2s. com*/ /* 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); try {//from ww w .java 2 s . c om //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 };// w w w .j av a 2 s . c om //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:Software_Jframes.chart.java
void print_pdf_report(JTable jTable5) { Access ac = new Access(); try {//ww w.ja va 2s . c om String filename = ac.chooseFile(); com.itextpdf.text.Document document = new com.itextpdf.text.Document(); PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf")); document.open(); document.add(new Paragraph("")); Image image1 = Image.getInstance("src/images/ROPA_Logo_without_claim.jpg"); document.add(new Paragraph("")); image1.scaleAbsolute(80, 50); image1.setAbsolutePosition(50, 800); document.add(image1); PdfPTable table = new PdfPTable(3); // 3 columns. DefaultTableModel dtm = (DefaultTableModel) jTable5.getModel(); Vector v = new Vector(); int count_row = dtm.getRowCount(); int count_col = dtm.getColumnCount(); for (int i = 0; i < count_row; i++) { for (int j = 0; j < count_col; j++) { table.addCell(new PdfPCell(new Paragraph(dtm.getValueAt(i, j) + ""))); } } table.setWidthPercentage(100); float[] columnWidths = { 2f, 1f, 1f }; table.setWidths(columnWidths); document.add(table); document.close(); JOptionPane.showMessageDialog(null, "Successfully Created."); } catch (Exception e) { e.printStackTrace(); } }
From source file:sqlsentinel.report.PDFGenerator.java
License:Open Source License
private static void createTable(Document document) throws BadElementException, DocumentException { float[] colsWidth = { 2f, 1f }; // Code 1 PdfPTable table = new PdfPTable(colsWidth); table.setWidthPercentage(100); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Url")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//from ww w . j a va 2 s . c o m c1 = new PdfPCell(new Phrase("type of vulnerability")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < urlVuln.size(); i++) { table.addCell((String) urlVuln.elementAt(i)); table.addCell((String) vulnType.elementAt(i)); } document.add(table); //url crawled table Paragraph preface = new Paragraph(); addEmptyLine(preface, 2); preface.add(new Paragraph("Url Crawled:", catFont)); addEmptyLine(preface, 1); document.add(preface); PdfPTable table2 = new PdfPTable(1); table2.setWidthPercentage(100); table2.setHeaderRows(1); for (int j = 0; j < urlCrawled.size(); j++) table2.addCell((String) urlCrawled.elementAt(j)); document.add(table2); }
From source file:src.servlets.ManageAdmin.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/* www . j a va2s . c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map m = request.getParameterMap(); if (m.containsKey("GetPDF")) { try { String Report = getServletContext().getRealPath("") + "admin\\PDF_Report.pdf"; FileOutputStream file = new FileOutputStream(Report); Document document = new Document(); document.addAuthor("K00140908"); PdfWriter.getInstance(document, file); ///////////////////////ADDING THE FILES TO PDF//////////////////// //Inserting Image in PDF String uploadPath = getServletContext().getRealPath("") + "images\\logo.gif"; Image img = Image.getInstance(uploadPath); img.scaleAbsolute(120f, 60f);// width,height of image in float // Inserting Title in PDF ORIGINAL // Font fontTitle=new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.WHITE); // Chunk title=new Chunk("PDF GENERATION in Java with iText", fontTitle); // title.setBackground(new BaseColor(255,102,0), 1f, 1f, 1f, 3f); // title.setLineHeight(30f); // title.setUnderline(BaseColor.BLACK,5f,0.5f,2f,0.5f,PdfContentByte.LINE_CAP_ROUND); Font fontTitle = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK); Chunk title = new Chunk("Lit Realty System Report", fontTitle); title.setLineHeight(30f); //Inserting Table in PDF PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); // Sets the width percentage that the table will occupy in the page table.setSpacingAfter(10f); table.setSpacingBefore(15f); table.setWidths(new float[] { 2f, 2f, 2f }); // Sets relative width of table Font fontHeader = new Font(Font.FontFamily.HELVETICA, 15, Font.BOLD, BaseColor.BLUE); PdfPCell headercell = new PdfPCell(new Phrase("Property Photo", fontHeader)); // Creates new cell in table headercell.setBackgroundColor(new BaseColor(230, 230, 243)); headercell.setPaddingBottom(5f); table.addCell(headercell); headercell = new PdfPCell(new Phrase("Property ID", fontHeader)); headercell.setBackgroundColor(new BaseColor(233, 233, 233)); headercell.setPaddingBottom(5f); table.addCell(headercell); headercell = new PdfPCell(new Phrase("Price", fontHeader)); headercell.setBackgroundColor(new BaseColor(233, 233, 233)); headercell.setPaddingBottom(5f); table.addCell(headercell); PdfPCell cell1 = new PdfPCell(img, false); table.addCell(cell1); table.addCell("134000"); table.addCell("213445"); table.addCell("134000"); //Inserting List com.itextpdf.text.List list = new com.itextpdf.text.List(true, 30); list.add(new ListItem("Example1")); list.add(new ListItem("Example2")); list.add(new ListItem("Example3")); //Adding elements into PDF Document document.open(); document.add(img); document.add(title); document.add(Chunk.NEWLINE); document.add(table); document.newPage(); document.add(new Chunk("List of Examples").setUnderline(+1f, -5f)); document.add(list); document.newPage(); document.add(new Chunk("List of Examples").setUnderline(+1f, -5f)); document.add(list); document.newPage(); document.add(new Chunk("List of Properts By Agent X").setUnderline(+1f, -5f)); //////////////////////GET Propertys From Entity/////////////// List<Properties> allPropertiesList = PropertiesDB.getAllProperties(); PdfPTable propertyTable = new PdfPTable(3); PdfPCell propertyHeadingcell1 = new PdfPCell(new Phrase("Photo")); PdfPCell propertyHeadingcell2 = new PdfPCell(new Phrase("Property ID")); PdfPCell propertyHeadingcell3 = new PdfPCell(new Phrase("Price")); propertyHeadingcell1.setBorder(Rectangle.NO_BORDER); propertyHeadingcell2.setBorder(Rectangle.NO_BORDER); propertyHeadingcell3.setBorder(Rectangle.NO_BORDER); propertyTable.addCell(propertyHeadingcell1); propertyTable.addCell(propertyHeadingcell2); propertyTable.addCell(propertyHeadingcell3); document.add(Chunk.NEWLINE); String uploadPathforPropertyPhoto = getServletContext().getRealPath("") + "images\\properties\\thumbnails\\"; Image propertyThumbnail; img.scaleAbsolute(120f, 60f);// width,height of image in float for (Properties anProperty : allPropertiesList) { propertyThumbnail = Image.getInstance(uploadPathforPropertyPhoto + anProperty.getPhoto()); PdfPCell propertycell1 = new PdfPCell(propertyThumbnail, false); propertycell1.setPaddingBottom(20); PdfPCell propertycell2 = new PdfPCell(new Phrase(anProperty.getListingNum().toString())); PdfPCell propertycell3 = new PdfPCell(new Phrase(anProperty.getPrice().toString())); propertycell1.setBorder(Rectangle.NO_BORDER); propertycell2.setBorder(Rectangle.NO_BORDER); propertycell3.setBorder(Rectangle.NO_BORDER); propertyTable.addCell(propertycell1); propertyTable.addCell(propertycell2); propertyTable.addCell(propertycell3); } document.add(Chunk.NEWLINE); document.add(propertyTable); //////////////////////GET Propertys From Entity/////////////// document.close(); file.close(); System.out.println("Pdf created successfully ! :)"); String filePath = Report; File downloadFile = new File(filePath); FileInputStream inStream = new FileInputStream(downloadFile); // if you want to use a relative path to context root: String relativePath = getServletContext().getRealPath(""); System.out.println("relativePath = " + relativePath); // obtains ServletContext ServletContext context = getServletContext(); // gets MIME type of the file String mimeType = context.getMimeType(filePath); if (mimeType == null) { // set to binary type if MIME mapping not found mimeType = "application/octet-stream"; } System.out.println("MIME type: " + mimeType); // modifies response response.setContentType(mimeType); response.setContentLength((int) downloadFile.length()); // forces download String headerKey = "Content-Disposition"; String headerValue = String.format("attachment; filename=\"%s\"", downloadFile.getName()); response.setHeader(headerKey, headerValue); // obtains response's output stream OutputStream outStream = response.getOutputStream(); byte[] buffer = new byte[4096]; int bytesRead = -1; while ((bytesRead = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, bytesRead); } inStream.close(); outStream.close(); ///////////////// processRequest(request, response); } catch (DocumentException ex) { Logger.getLogger(ManageAdmin.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:support.plus.reportit.export.export_pdf_class.java
License:Open Source License
public PdfPTable createFirstTable(String filenumber, String filetag, String startdate, String enddate, String TextUserNameString, String TextUserNameBossString, String mondayText1, String mondayText2, String mondayText3, String mondayText4, String mondayText5, String mondayText6, String tuesdayText1, String tuesdayText2, String tuesdayText3, String tuesdayText4, String tuesdayText5, String tuesdayText6, String wednesdayText1, String wednesdayText2, String wednesdayText3, String wednesdayText4, String wednesdayText5, String wednesdayText6, String thursdayText1, String thursdayText2, String thursdayText3, String thursdayText4, String thursdayText5, String thursdayText6, String fridayText1, String fridayText2, String fridayText3, String fridayText4, String fridayText5, String fridayText6, String mondayTextTime1, String mondayTextTime2, String mondayTextTime3, String mondayTextTime4, String mondayTextTime5, String mondayTextTime6, String tuesdayTextTime1, String tuesdayTextTime2, String tuesdayTextTime3, String tuesdayTextTime4, String tuesdayTextTime5, String tuesdayTextTime6, String wednesdayTextTime1, String wednesdayTextTime2, String wednesdayTextTime3, String wednesdayTextTime4, String wednesdayTextTime5, String wednesdayTextTime6, String thursdayTextTime1, String thursdayTextTime2, String thursdayTextTime3, String thursdayTextTime4, String thursdayTextTime5, String thursdayTextTime6, String fridayTextTime1, String fridayTextTime2, String fridayTextTime3, String fridayTextTime4, String fridayTextTime5, String fridayTextTime6) { String mon = String.valueOf(context.getResources().getText(R.string.monday_short)); String tues = String.valueOf(context.getResources().getText(R.string.tuesday_short)); String wed = String.valueOf(context.getResources().getText(R.string.wednesday_short)); String thurs = String.valueOf(context.getResources().getText(R.string.thursday_short)); String fri = String.valueOf(context.getResources().getText(R.string.friday_short)); String hours = String.valueOf(context.getResources().getText(R.string.hours)); String day = String.valueOf(context.getResources().getText(R.string.day)); String reportNr = String.valueOf(context.getResources().getText(R.string.report_nr)); String weekFrom = String.valueOf(context.getResources().getText(R.string.weekFrom)); String weekTo = String.valueOf(context.getResources().getText(R.string.weekTo)); String firmName = String.valueOf(context.getResources().getText(R.string.firmName)); String instructorName = String.valueOf(context.getResources().getText(R.string.instructorName)); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(450 / 5.23f); try {/*from w w w . j a v a 2 s .c o m*/ table.setWidths(new int[] { 1, 9, 1 }); } catch (DocumentException e) { e.printStackTrace(); } PdfPCell cell; Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD); cell = new PdfPCell( new Phrase(reportNr + " " + filenumber + " " + weekFrom + " " + startdate + " " + weekTo + " " + enddate, fontbold)); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase(firmName + " " + TextUserNameString + " " + instructorName + " " + TextUserNameBossString)); cell.setColspan(3); table.addCell(cell); table.addCell(day); cell = new PdfPCell(new Phrase(filetag)); cell.setColspan(1); table.addCell(cell); table.addCell(hours); table.addCell(mon); cell = new PdfPCell(new Phrase(mondayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime6); table.addCell(tues); cell = new PdfPCell(new Phrase(tuesdayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime6); table.addCell(wed); cell = new PdfPCell(new Phrase(wednesdayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime6); table.addCell(thurs); cell = new PdfPCell(new Phrase(thursdayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime6); table.addCell(fri); cell = new PdfPCell(new Phrase(fridayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime6); createSecondTable(); return table; }
From source file:support.plus.reportit.export.export_pdf_class.java
License:Open Source License
public PdfPTable createSecondTable() { PdfPTable table = new PdfPTable(3); table.setWidthPercentage(450 / 5.23f); try {/*from w w w . j a va2 s. c o m*/ table.setWidths(new int[] { 1, 9, 1 }); } catch (DocumentException e) { e.printStackTrace(); } PdfPCell cell; String signatures = String.valueOf(context.getResources().getText(R.string.signatures)); String trainee = String.valueOf(context.getResources().getText(R.string.trainee_only)); String instructor = String.valueOf(context.getResources().getText(R.string.instructor_only)); String deputy = String.valueOf(context.getResources().getText(R.string.desputy)); String notes = String.valueOf(context.getResources().getText(R.string.notes)); cell = new PdfPCell(new Phrase("\n\n " + signatures + "\n" + " __________ __________ __________ __________" + "\n " + trainee + " " + instructor + " " + deputy + " " + notes)); cell.setColspan(3); table.addCell(cell); return table; }
From source file:Tables.Printer.java
public void genTrans(TableView gentab, TableColumn name, TableColumn desc, TableColumn amt, TableColumn date, long total, String incOrExp) { try {/*w ww . jav a2 s. co m*/ // Image im = Image.getInstance("src/njeiaccount/njei_img/accountcreation-icon.png"); // im.scaleAbsolute(150f, 150f); // im.setAbsolutePosition(25,50); // im.setBackgroundColor(BaseColor.PINK); dNow = new Date(); String app = this.datForFile.format(dNow); String file = "\\Documents\\NjieAB_receipts\\general transactions\\GenTransRec" + app + ".pdf"; System.out.println("file is " + file); fs = new FileOutputStream(System.getProperties().getProperty("user.home") + file); //this is for windows. since am developing on linux, i will use the next line. But for production version, i will enable the first optionand comment the second option as most users will be on the windows system. Or, will detect the OS and decide where to keept the files. Better idea //fs = new FileOutputStream(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf"); Document doc = new Document(PageSize.A4, 20, 20, 20, 20); PdfWriter writer = PdfWriter.getInstance(doc, fs); //specify column widths float[] columnWidths = { 4f, 5f, 1.5f, 2f }; PdfPTable table = new PdfPTable(columnWidths); //special font sizes Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 10); // set table width a percentage of the page width table.setWidthPercentage(90f); PdfPCell cell = new PdfPCell(new Phrase("\nRECIEPT FOR ")); cell.setColspan(6); cell.setHorizontalAlignment(2); doc.open(); //doc.add(im); header(doc, "General " + incOrExp + " Transaction Table"); doc.add(cell); System.out.println(doc.leftMargin()); //insert column headings insertTableHeading(table, "Transaction Name ", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Description of Transaction", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Amount", Element.ALIGN_MIDDLE, 1, bfBold12); insertTableHeading(table, "Date ", Element.ALIGN_MIDDLE, 1, bfBold12); table.setHeaderRows(1); /*Now i have to fill the table */ for (int i = 0; i < gentab.getItems().size(); i++) { insertCell(table, name.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, desc.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, amt.getCellData(i).toString(), Element.ALIGN_LEFT, 1, bf12); insertCell(table, date.getCellData(i).toString(), Element.ALIGN_RIGHT, 1, bf12); } insertCell(table, "Total ", Element.ALIGN_RIGHT, 2, bfBold12); insertCell(table, String.valueOf(total), Element.ALIGN_LEFT, 3, bfBold12); insertCell(table, "", Element.ALIGN_RIGHT, 4, bfBold12); doc.add(table); footer(doc); // this is rgw footer of the page doc.addCreationDate(); doc.close(); System.out.println("finished the printing job"); //Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home")+"root/Desktop/reciept.pdf")); try { Desktop.getDesktop().open(new File(System.getProperties().getProperty("user.home") + file)); } catch (IOException iOException) { System.out.println("failed opening the file"); iOException.printStackTrace(); } } catch (Exception sd) { sd.printStackTrace(); Dialogs.create().title("Printer Error").masthead("Errro In Printing File").message( sd.getMessage() + " : " + sd.getCause() + " Caused By " + sd.getCause() + "--" + sd.toString()) .showError(); } finally { } }