List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage
public void setWidthPercentage(final float widthPercentage)
From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java
public static void printToPDFBoss(ArrayList<Person> workers, EventGig event) throws IOException, DocumentException { String filename = event.getName() + " Boss" + ".pdf"; String path = event.getData() + " " + event.getName() + "//"; //Rectangle rect = new Rectangle(0, 595, 8, 0); Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0); //Document document = new Document(rect); //document.setMargins(0, 0, 0, 0); BaseFont bf;// www .j a va 2s. c o m //BaseFont bf2; // bf = BaseFont.createFont("arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); bf = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); //bf2 = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); com.itextpdf.text.Font ft = new com.itextpdf.text.Font(bf, 9); //com.itextpdf.text.Font ft2 = new com.itextpdf.text.Font(bf2,9); PdfWriter.getInstance(document, new FileOutputStream(path + filename)); document.open(); Paragraph p = new Paragraph(event.getName() + " " + event.getData(), ft); p.setAlignment(Element.ALIGN_CENTER); document.add(p); document.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(workers.size() + 1); table.setWidthPercentage(98); PdfPCell cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); for (Person tempPerson : workers) { cell = new PdfPCell(new Paragraph(tempPerson.getName(), ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } if (event.isZaladunekScenaDach()) { cell = new PdfPCell(new Paragraph("Za. Sc./Dach", ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getZaladunekScenaDachWyplata() > 0) { cell = new PdfPCell( new Paragraph(String.format("%.2f", tempPerson.getZaladunekScenaDachWyplata()), ft)); cell.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isZaladunekTechniki()) { cell = new PdfPCell(new Phrase("Za. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getZaladunekTechnikiWyplata() > 0) { cell = new PdfPCell( new Paragraph(String.format("%.2f", tempPerson.getZaladunekTechnikiWyplata()), ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRozladunekScenaDach()) { cell = new PdfPCell(new Phrase("Roz Sc/Dach", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRozladunekScenaDachWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRozladunekScenaDachWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRozladunekTechniki()) { cell = new PdfPCell(new Phrase("Roz. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRozladunekTechnikiWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRozladunekTechnikiWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazDachu()) { cell = new PdfPCell(new Phrase("Mon. Dach", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazDachuWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getMontazDachuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazDzwieku()) { cell = new PdfPCell(new Phrase("Mon. Dw.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazDzwiekuWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getMontazDzwiekuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazSceny()) { cell = new PdfPCell(new Phrase("Mon. Sc.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazScenyWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getMontazScenyWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazSwiatla()) { cell = new PdfPCell(new Phrase("Mon. w.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazSwiatlaWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getMontazSwiatlaWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isMontazTechniki()) { cell = new PdfPCell(new Phrase("Mon. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getMontazTechnikiWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getMontazTechnikiWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazDachu()) { cell = new PdfPCell(new Phrase("Dem. Dach", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazDachuWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazDachuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazDzwieku()) { cell = new PdfPCell(new Phrase("Dem. Dw.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazDzwiekuWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazDzwiekuWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazSceny()) { cell = new PdfPCell(new Phrase("Dem. Sc.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazScenyWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazScenyWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazSwiatla()) { cell = new PdfPCell(new Phrase("Dem. w.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazSwiatlaWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazSwiatlaWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDemontazTechniki()) { cell = new PdfPCell(new Phrase("Dem. Tech.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDemontazTechnikiWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getDemontazTechnikiWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isDyzur()) { cell = new PdfPCell(new Phrase("Dyur", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getDyzurWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getDyzurWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase("")); table.addCell(cell); } } } if (event.isTechnikSceny()) { cell = new PdfPCell(new Phrase("Technik Sc.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getTechnikScenyWyplata() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getTechnikScenyWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRealizacjaFOH()) { cell = new PdfPCell(new Phrase("Real. FOH", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRealizacjaFOHWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRealizacjaFOHWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRealizacjaMON()) { cell = new PdfPCell(new Phrase("Real. MON", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRealizacjaMONWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRealizacjaMONWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (event.isRealizacjaSwiatla()) { cell = new PdfPCell(new Phrase("Real. w.", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getRealizacjaSwiatlaWyplata() > 0) { cell = new PdfPCell( new Phrase(String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } if (true) { cell = new PdfPCell(new Phrase("Premia", ft)); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getPremia() > 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getPremia()), ft)); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } } Paragraph ph = new Paragraph("Razem", ft); //cell = new PdfPCell(new Phrase(ph)); cell.addElement(ph); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); for (Person tempPerson : workers) { if (tempPerson.getSumaWyplata() >= 0) { cell = new PdfPCell(new Phrase(String.format("%.2f", tempPerson.getSumaWyplata()) + " z", ft)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(" ")); table.addCell(cell); } } // for (Object obj : table.getChunks()) { // if (obj instanceof PdfPCell) { // System.out.println("jest PdfCell"); // PdfPCell tempCell = (PdfPCell) obj; // tempCell.setVerticalAlignment(Element.ALIGN_CENTER); // //tempCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // } // // } table.setHorizontalAlignment(Element.ALIGN_CENTER); document.add(table); document.close(); }
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable tabla2(List<Nomina> no) throws DocumentException { //Instanciamos una tabla de 3 columnas PdfPTable tabla = new PdfPTable(4); tabla.setWidthPercentage(100); tabla.setWidths(new float[] { 1, 1, 1, 3 }); //Declaramos un objeto para manejar las celdas PdfPCell celda;// w w w . j a v a 2 s . c om celda = new PdfPCell(new Phrase("Codigo:")); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase("" + no.get(0).getEmpleadoCodigo().getCodigo())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Nombre:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getNombre())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Cedula:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getCedula())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Cargo:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getCargoCargoid().getCargo())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Dias Lab:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { dt = dtC.findBySingle2("periodoIdperiodo", no.get(0).getPeriodoIdperiodo(), "empleadoCodigo", no.get(0).getEmpleadoCodigo()); celda = new PdfPCell(new Phrase("" + dt.getDias())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } celda = new PdfPCell(new Phrase("Sueldo:")); //celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (!no.isEmpty()) { celda = new PdfPCell(new Phrase("" + no.get(0).getEmpleadoCodigo().getSalario())); //celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } return tabla; }
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable firma() throws DocumentException { PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(100); tabla.setWidths(new float[] { 2, 1, 2 }); //Declaramos un objeto para manejar las celdas PdfPCell celda;//from www . jav a 2s . c o m celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.BOTTOM); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.BOTTOM); tabla.addCell(celda); celda = new PdfPCell(new Phrase("JEFE ADMINISTRATIVO")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("EMPLEADO")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); return tabla; }
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable tabla3(List<Nomina> no) throws DocumentException { //Instanciamos una tabla de 3 columnas PdfPTable tabla = new PdfPTable(4); tabla.setWidthPercentage(100); tabla.setWidths(new float[] { 1, 3, 1, 1 }); //Declaramos un objeto para manejar las celdas PdfPCell celda;//ww w. j a va2s . c o m celda = new PdfPCell(new Phrase("CODIGO")); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); tabla.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCION")); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); celda = new PdfPCell(new Phrase("VLR.DEVEN")); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); celda.setBorderWidth(1); celda.setVerticalAlignment(Element.ALIGN_TOP); tabla.addCell(celda); celda = new PdfPCell(new Phrase("VLR.DEDUC")); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); double totalDev = 0, totalDed = 0; for (Nomina nomina : no) { celda = new PdfPCell(new Phrase("" + nomina.getConceptoIdconcepto().getCodigo())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); celda = new PdfPCell(new Phrase("" + nomina.getConceptoIdconcepto().getConcepto())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (nomina.getConceptoIdconcepto().getTipo().equals("DEVENGADO")) { totalDev += nomina.getValor(); celda = new PdfPCell(new Phrase("" + nomina.getValor())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celda); } else { celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } if (nomina.getConceptoIdconcepto().getTipo().equals("DEDUCIDO")) { totalDed += nomina.getValor(); celda = new PdfPCell(new Phrase("" + nomina.getValor())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celda); } else { celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } } celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("TOTALES")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("" + totalDev)); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); celda.setBorder(Rectangle.TOP); tabla.addCell(celda); celda = new PdfPCell(new Phrase(" " + totalDed)); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); celda.setBorder(Rectangle.TOP); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("NETO A PAGAR")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase(" " + (totalDev - totalDed))); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celda); celda = new PdfPCell(new Phrase(" ")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); return tabla; }
From source file:com.vectorprint.report.itext.style.stylers.Table.java
License:Open Source License
private PdfPTable style(PdfPTable t) throws VectorPrintException { super.style(t, null); t.setWidthPercentage(getRelwidth()); try {/* w w w. j a v a2 s.c o m*/ float[] w = getWidths(); t.setWidths(w); t.setTotalWidth(w); t.setHeaderRows(getHeaderrows()); t.setFooterRows(getFooterrows()); } catch (DocumentException ex) { throw new VectorPrintException("number of widths differs from number of columns in table", ex); } return t; }
From source file:com.vimbox.hr.LicensePDFGenerator.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w. j a v a 2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); String fileName = request.getParameter("license_name"); String ext = fileName.substring(fileName.lastIndexOf(".") + 1); String path = System.getProperty("user.dir") + "/documents/licenses/" + fileName; path = path.replaceAll("%20", " "); if (ext.equalsIgnoreCase("pdf")) { FileInputStream baos = new FileInputStream(path); OutputStream os = response.getOutputStream(); byte buffer[] = new byte[8192]; int bytesRead; while ((bytesRead = baos.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } os.flush(); os.close(); } else { try { // Document Settings // Document document = new Document(); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); // Loading MC // PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); // the cell object PdfPCell cell; Image img = Image.getInstance(path); int indentation = 0; float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin() - indentation) / img.getWidth()) * 100; img.scalePercent(scaler); //img.scaleAbsolute(80f, 80f); cell = new PdfPCell(img); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); document.add(table); //-----------------------------------// document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } } }
From source file:comisionesafis.informes.CintaComisiones.java
public boolean generar() { // Abrimos el fichero de comisiones String sSQL = ""; Statement stmt;/*from w w w .ja v a2s . co m*/ ResultSet rsComisiones; ResultSet rsBanco; String cuenta; // Generamos la sentencia de Seleccin de Datos try { // Generamos el PDF Document documento = new Document(PageSize.A4, 80, 80, 50, 50); FileOutputStream salida = new FileOutputStream(FICHERO_PDF); PdfWriter writer = PdfWriter.getInstance(documento, salida); writer.setInitialLeading(0); // Obtenemos una instancia de nuestro manejador de eventos CintaComisionesPie pie = new CintaComisionesPie(); //Asignamos el manejador de eventos al escritor. writer.setPageEvent(pie); // Abrimos el Documento documento.open(); sSQL = "SELECT * "; sSQL += " FROM ResumenComisiones"; sSQL += " ORDER BY CodAgente"; stmt = conexion.createStatement(); rsComisiones = stmt.executeQuery(sSQL); Paragraph Titulo = new Paragraph(); Titulo.setAlignment(Element.ALIGN_CENTER); Titulo.add("CINTA COMISIONES"); float[] anchuras = { 1f, 1.5f, 3f, 4f, 1f, 1.5f }; PdfPTable table = new PdfPTable(anchuras); table.setWidthPercentage(100); table.setSpacingBefore(15f); table.setSpacingAfter(10f); PdfPCell celda; // Tipo de letra para la tabla Font font = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL); celda = new PdfPCell(new Phrase("Agente", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Importe", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Cuenta Bancaria", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Nombre", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Irpf", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase("Total", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); while (rsComisiones.next()) { // Buscamos la Cuenta Bancaria sSQL = "SELECT * "; sSQL += " FROM Agentes"; sSQL += " WHERE CodAgente='" + rsComisiones.getString("CodAgente") + "'"; stmt = conexion.createStatement(); rsBanco = stmt.executeQuery(sSQL); if (!rsBanco.next()) { cuenta = " "; } else { cuenta = rsBanco.getString("Banco"); cuenta += rsBanco.getString("Sucursal"); cuenta += rsBanco.getString("DC"); cuenta += rsBanco.getString("Cuenta"); } // Datos del agente celda = new PdfPCell(new Phrase(rsComisiones.getString("CodAgente"), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase( Numeros.formateaDosDecimales(Double.parseDouble(rsComisiones.getString("TotalComisiones"))), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase(cuenta, font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(celda); celda = new PdfPCell(new Phrase(rsComisiones.getString("Nombre"), font)); celda.setBorder(Rectangle.NO_BORDER); table.addCell(celda); celda = new PdfPCell(new Phrase( Numeros.formateaDosDecimales(Double.parseDouble(rsComisiones.getString("TotalRetencion"))), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase( Numeros.formateaDosDecimales(Double.parseDouble(rsComisiones.getString("TotalPagar"))), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); } documento.add(Titulo); documento.add(new Paragraph(" ")); // Agregamos la tabla al documento documento.add(table); documento.close(); return true; } catch (Exception e) { return false; } }
From source file:comisionesafis.informes.LiquidacionComisiones.java
private PdfPTable creaTabla() { float[] anchuras = { 2f, 1f, 1f, 1f, 1f }; PdfPTable tabla = new PdfPTable(anchuras); tabla.setWidthPercentage(100); tabla.setSpacingBefore(4f);//from w w w .j a v a2s . c o m return tabla; }
From source file:Controller.ControllerCompra.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w . j a v a 2s. c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); if (request.getParameter("action") != null) { //int estado = 0; String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); String action = request.getParameter("action"); switch (action) { case "Registrar": { String documentoUsuario = (request.getParameter("documentoUsuario")); String facturaProveedor = (request.getParameter("txtNumeroFactura")); String nombreProveedor = (request.getParameter("txtNombre")); int lenght = Integer.parseInt(request.getParameter("size")); int totalCompra = Integer.parseInt(request.getParameter("txtTotalCompra")); listObjDetalleMovimientos = new ArrayList<>(); for (int i = 0; i < lenght; i++) { _objDetalleMovimiento = new ObjDetalleMovimiento(); _objDetalleMovimiento .setIdArticulo(Integer.parseInt(request.getParameter("lista[" + i + "][idArticulo]"))); _objDetalleMovimiento .setCantidad(Integer.parseInt(request.getParameter("lista[" + i + "][cantidad]"))); _objDetalleMovimiento.setPrecioArticulo( Integer.parseInt(request.getParameter("lista[" + i + "][precioArticulo]"))); _objDetalleMovimiento.setTotalDetalleMovimiento( _objDetalleMovimiento.getCantidad() * _objDetalleMovimiento.getPrecioArticulo()); _objDetalleMovimiento.setDescuento(lenght); listObjDetalleMovimientos.add(_objDetalleMovimiento); } _objUsuario.setDocumentoUsuario(documentoUsuario); _objCompra.setFacturaProveedor(facturaProveedor); _objCompra.setNombreProveedor(nombreProveedor); _objCompra.setTotalCompra(totalCompra); daoModelCompra = new ModelCompra(); String salida = Mensaje(daoModelCompra.Add(_objCompra, _objUsuario, listObjDetalleMovimientos), "La compra ha sido registrada", "Ha ocurrido un error"); daoModelCompra.Signout(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(salida); break; } case "Consultar": { int id = Integer.parseInt(request.getParameter("id")); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(consultarDetalle(id)); break; } case "Enlistar": { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(getTableCompra()); break; } //<editor-fold defaultstate="collapsed" desc="PDF mediante iText"> case "Imprimir": { response.setContentType("application/pdf"); try { Locale loc = Locale.getDefault(); NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(loc); //Primero obtengo el id del Movimiento int id = Integer.parseInt(request.getParameter("id")); //Obtengo el reporte a manera de Map Map material = reporte(id); //Topo ese reporte y lo divido, primero en la compra y luego el detalle Map<String, String> compra = (Map) material.get("Compra"); List<Map> detalle = (List) material.get("Detalle"); //Creo el documento y obtengo el canal de comunicacion con el servidor, para luego enviar el documento. Document document = new Document(); OutputStream os = response.getOutputStream(); //Creo una instancia a partir del documento y del canal PdfWriter.getInstance(document, os); //Abro el documento document.open(); Image logo = Image.getInstance(url + "/public/images/logo.png"); logo.scaleAbsolute(new Rectangle(logo.getPlainWidth() / 4, logo.getPlainHeight() / 4)); document.add(logo); //Creo una fuente para la letra en negrilla final Font helveticaBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); //Escribo y agrego un primer parrafo con los datos basicos de la compra Paragraph headerDerecha = new Paragraph(); headerDerecha.add(new Chunk("Nombre del Proveedor: ", helveticaBold)); headerDerecha.add(new Chunk(compra.get("nombreProveedor") + "\n")); headerDerecha.add(new Chunk("Factura del Proveedor: ", helveticaBold)); headerDerecha.add(new Chunk(compra.get("facturaProveedor") + "\n")); headerDerecha.add(new Chunk("Fecha Compra: ", helveticaBold)); headerDerecha.add(new Chunk(compra.get("fechaCompra") + "\n")); //Escribo y agrego un segundo parrafo con los datos basicos de Stelarte Paragraph headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Stelarte.Decoracion \n", helveticaBold)); headerIzquierda.add(new Chunk("Direccin: ", helveticaBold)); headerIzquierda.add(new Chunk("Calle Falsa 123 # 12a34\n")); headerIzquierda.add(new Chunk("Telfono: ", helveticaBold)); headerIzquierda.add(new Chunk("2583697 \n")); //Agrego los dos anteriores parrafos al Header PdfPTable header = new PdfPTable(2); header.getDefaultCell().setBorder(0); header.addCell(headerIzquierda); header.addCell(headerDerecha); header.setWidthPercentage(100f); header.setSpacingAfter(20); document.add(header); //Creo la tabla del detalle PdfPTable tablaDetalle = new PdfPTable(new float[] { 1, 3, 2, 2 }); tablaDetalle.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); //Creo el titulo, le quito el borde, le digo que ocupara cuatro columnas y que ser centrado PdfPCell tituloCell = new PdfPCell(new Phrase("Detalle de Compra", helveticaBold)); tituloCell.setBorder(0); tituloCell.setColspan(4); tituloCell.setHorizontalAlignment(Element.ALIGN_CENTER); tablaDetalle.addCell(tituloCell); //Aqui creo cada cabecera tablaDetalle.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); tablaDetalle.addCell(new Phrase("ID", helveticaBold)); tablaDetalle.addCell(new Phrase("Nombre", helveticaBold)); tablaDetalle.addCell(new Phrase("Cantidad", helveticaBold)); tablaDetalle.addCell(new Phrase("Valor", helveticaBold)); tablaDetalle.getDefaultCell().setBackgroundColor(null); //Aqui agrego la tabla cada articulo. for (Map<String, String> next : detalle) { tablaDetalle.addCell(next.get("idArticulo")); tablaDetalle.addCell(next.get("descripcionArticulo")); tablaDetalle.addCell(next.get("cantidad")); tablaDetalle .addCell(currencyFormatter.format(Integer.parseInt(next.get("precioArticulo")))); } //Creo el Footer headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Total: ", helveticaBold)); headerIzquierda .add(new Chunk(currencyFormatter.format(Integer.parseInt(compra.get("totalCompra"))))); PdfPCell footerCell = new PdfPCell(headerIzquierda); footerCell.setBorder(0); footerCell.setColspan(4); footerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tablaDetalle.addCell(footerCell); //Establesco el tamao y posicion de la tabla, luego la agrego al documento tablaDetalle.setWidthPercentage(100f); tablaDetalle.setHorizontalAlignment(Element.ALIGN_RIGHT); document.add(tablaDetalle); //Cierro el documento y lo envio con flush. document.close(); response.setHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\""); os.flush(); os.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } break; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="PDF mediante iReports"> case "Imprimir2": { try { int id = Integer.parseInt(request.getParameter("id")); String source = url + "/reports/newReport1.jrxml"; JasperPrint jasperPrint = null; JasperReport jasperReport = null; JasperDesign jasperDesign = null; System.out.println(source); String reportPath = request.getServletContext().getRealPath("reports") + "\\newReport1.jrxml"; jasperDesign = JRXmlLoader.load(reportPath); jasperReport = JasperCompileManager.compileReport(jasperDesign); jasperPrint = JasperFillManager.fillReport(jasperReport, reporte(id), daoModelCompra.getConnection()); JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); } catch (Exception ex) { for (StackTraceElement ruta : ex.getStackTrace()) { System.err.println(ruta); } } } break; //</editor-fold> } } }
From source file:Controller.ControllerVenta.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//ww w . ja v a 2 s.c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); if (request.getParameter("action") != null) { String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); String action = request.getParameter("action"); switch (action) { case "Registrar": { String documentoUsuario = (request.getParameter("documentoUsuario")); String documentoCliente = null; String nombreCliente = null; int numeroVenta = 0; if (Validador.validarDocumento(request.getParameter("documentoCliente")) & Validador.validarNombresCompletos(request.getParameter("txtNombreCliente")) & Validador.validarNumero(request.getParameter("txtNumeroVenta"))) { documentoCliente = (request.getParameter("documentoCliente")); nombreCliente = (request.getParameter("txtNombreCliente")); numeroVenta = Integer.parseInt(request.getParameter("txtNumeroVenta")); } else { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(Mensaje(false, null, "Ha ingresado datos incorrectos")); break; } int lenght = Integer.parseInt(request.getParameter("size")); int totalCompra = Integer.parseInt(request.getParameter("txtTotalVenta")); listOjbDetalleMovimientos = new ArrayList<>(); for (int i = 0; i < lenght; i++) { _objDetalleMovimiento = new ObjDetalleMovimiento(); _objDetalleMovimiento .setIdArticulo(Integer.parseInt(request.getParameter("lista[" + i + "][idArticulo]"))); _objDetalleMovimiento .setCantidad(Integer.parseInt(request.getParameter("lista[" + i + "][cantidad]"))); _objDetalleMovimiento.setPrecioArticulo( Integer.parseInt(request.getParameter("lista[" + i + "][precioArticulo]"))); _objDetalleMovimiento.setTotalDetalleMovimiento( _objDetalleMovimiento.getCantidad() * _objDetalleMovimiento.getPrecioArticulo()); _objDetalleMovimiento.setDescuento(lenght); listOjbDetalleMovimientos.add(_objDetalleMovimiento); } _objUsuario.setDocumentoUsuario(documentoUsuario); _objVenta.setIdVenta(numeroVenta); _objVenta.setDocumentoCliente(documentoCliente); _objVenta.setNombreCliente(nombreCliente); _objVenta.setTotalVenta(totalCompra); daoModelVenta = new ModelVenta(); String salida = Mensaje(daoModelVenta.Add(_objVenta, _objUsuario, listOjbDetalleMovimientos), "La venta ha sido registrada", "Ha ocurrido un error"); daoModelVenta.Signout(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(salida); break; } case "Consultar": { int id = Integer.parseInt(request.getParameter("id")); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(consultarDetalle(id)); break; } case "Enlistar": { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(getTableVenta()); break; } case "Contador": { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(getContador()); break; } case "Imprimir": { response.setContentType("application/pdf"); try { Locale loc = Locale.getDefault(); NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(loc); //Primero obtengo el id del Movimiento int id = Integer.parseInt(request.getParameter("id")); //Obtengo el reporte a manera de Map Map material = reporte(id); //Topo ese reporte y lo divido, primero en la compra y luego el detalle Map<String, String> venta = (Map) material.get("Venta"); List<Map> detalle = (List) material.get("Detalle"); //Creo el documento y obtengo el canal de comunicacion con el servidor, para luego enviar el documento. Document document = new Document(); OutputStream os = response.getOutputStream(); //Creo una instancia a partir del documento y del canal PdfWriter.getInstance(document, os); //Abro el documento document.open(); Image logo = Image.getInstance(url + "/public/images/logo.png"); logo.scaleAbsolute(new Rectangle(logo.getPlainWidth() / 4, logo.getPlainHeight() / 4)); document.add(logo); //Creo una fuente para la letra en negrilla final Font helveticaBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); //Escribo y agrego un primer parrafo con los datos basicos de la compra Paragraph headerDerecha = new Paragraph(); headerDerecha.add(new Chunk("Id. de la Venta: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("numeroVenta") + "\n")); headerDerecha.add(new Chunk("Nombre del Cliente: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("nombreCliente") + "\n")); headerDerecha.add(new Chunk("Documento del Cliente: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("documentoCliente") + "\n")); headerDerecha.add(new Chunk("Fecha Venta: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("fechaVenta") + "\n")); //Escribo y agrego un segundo parrafo con los datos basicos de Stelarte Paragraph headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Stelarte.Decoracion \n", helveticaBold)); headerIzquierda.add(new Chunk("Direccin: ", helveticaBold)); headerIzquierda.add(new Chunk("Calle Falsa 123 # 12a34\n")); headerIzquierda.add(new Chunk("Telfono: ", helveticaBold)); headerIzquierda.add(new Chunk("2583697 \n")); //Agrego los dos anteriores parrafos al Header PdfPTable header = new PdfPTable(2); header.getDefaultCell().setBorder(0); header.addCell(headerIzquierda); header.addCell(headerDerecha); header.setWidthPercentage(100f); header.setSpacingAfter(20); document.add(header); //Creo la tabla del detalle PdfPTable tablaDetalle = new PdfPTable(new float[] { 1, 3, 2, 2 }); tablaDetalle.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); //Creo el titulo, le quito el borde, le digo que ocupara cuatro columnas y que ser centrado PdfPCell tituloCell = new PdfPCell(new Phrase("Detalle de Venta", helveticaBold)); tituloCell.setBorder(0); tituloCell.setColspan(4); tituloCell.setHorizontalAlignment(Element.ALIGN_CENTER); tablaDetalle.addCell(tituloCell); //Aqui creo cada cabecera tablaDetalle.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); tablaDetalle.addCell(new Phrase("ID", helveticaBold)); tablaDetalle.addCell(new Phrase("Nombre", helveticaBold)); tablaDetalle.addCell(new Phrase("Cantidad", helveticaBold)); tablaDetalle.addCell(new Phrase("Valor", helveticaBold)); tablaDetalle.getDefaultCell().setBackgroundColor(null); //Aqui agrego la tabla cada articulo. for (Map<String, String> next : detalle) { tablaDetalle.addCell(next.get("idArticulo")); tablaDetalle.addCell(next.get("descripcionArticulo")); tablaDetalle.addCell(next.get("cantidad")); tablaDetalle .addCell(currencyFormatter.format(Integer.parseInt(next.get("precioArticulo")))); } //Creo el Footer headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Total: ", helveticaBold)); headerIzquierda .add(new Chunk(currencyFormatter.format(Integer.parseInt(venta.get("totalVenta"))))); PdfPCell footerCell = new PdfPCell(headerIzquierda); footerCell.setBorder(0); footerCell.setColspan(4); footerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tablaDetalle.addCell(footerCell); //Establesco el tamao y posicion de la tabla, luego la agrego al documento tablaDetalle.setWidthPercentage(100f); tablaDetalle.setHorizontalAlignment(Element.ALIGN_RIGHT); document.add(tablaDetalle); //Cierro el documento y lo envio con flush. document.close(); response.setHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\""); os.flush(); os.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } break; } } } }