List of usage examples for com.itextpdf.text.pdf PdfPTable PdfPTable
public PdfPTable(final PdfPTable table)
PdfPTable
. 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);//from w ww . j a v a2 s. co m tabla.setWidths(new float[] { 1, 3, 1, 1 }); //Declaramos un objeto para manejar las celdas PdfPCell celda; 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.vimbox.hr.LicensePDFGenerator.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . j a v a2 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:com.wabacus.system.component.application.report.abstractreport.AbsReportType.java
License:Open Source License
protected void showTitleOnPdf() throws Exception { PdfPTable tableTitle = new PdfPTable(1); tableTitle.setTotalWidth(pdfwidth);//w ww . j a v a 2 s . c o m tableTitle.setLockedWidth(true);// int titlefontsize = 0; if (this.pdfbean != null) titlefontsize = this.pdfbean.getTitlefontsize(); if (titlefontsize <= 0) titlefontsize = 10; Font headFont = new Font(PdfAssistant.getInstance().getBfChinese(), titlefontsize, Font.BOLD); PdfPCell cell = new PdfPCell( new Paragraph(rbean.getTitle(rrequest) + " " + rbean.getSubtitle(rrequest), headFont)); cell.setColspan(1); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableTitle.addCell(cell); document.add(tableTitle); }
From source file:com.wabacus.system.component.application.report.abstractreport.AbsReportType.java
License:Open Source License
protected void createNewPdfPage() { try {// w ww . j a v a 2 s. c om if (this.pdfrowindex == 0) { if (pdfbean != null && pdfbean.getInterceptorObj() != null) { pdfbean.getInterceptorObj().beforeDisplayPdfPageWithoutTemplate(document, this); } showTitleOnPdf(); } else { if (pdfDataTable != null) { document.add(pdfDataTable);//??document if (pdfbean != null && pdfbean.getInterceptorObj() != null) { pdfbean.getInterceptorObj().afterDisplayPdfPageWithoutTemplate(document, this); } } if (pdfbean != null && pdfbean.getInterceptorObj() != null) { pdfbean.getInterceptorObj().beforeDisplayPdfPageWithoutTemplate(document, this); } document.newPage(); if (isFullpagesplit) showTitleOnPdf(); } } catch (Exception e) { throw new WabacusRuntimeException( "" + rbean.getPath() + "?PDF?", e); } if (totalcolcount < 0) totalcolcount = getTotalColCount(); pdfDataTable = new PdfPTable(totalcolcount); pdfDataTable.setTotalWidth(pdfwidth); }
From source file:com.xumpy.itext.services.HeaderFooter.java
@Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable header = new PdfPTable(3); try {/*from w w w .j a va 2 s . c o m*/ header.setWidths(new int[] { 24, 24, 24 }); header.setTotalWidth(527); header.setLockedWidth(true); header.getDefaultCell().setFixedHeight(20); header.getDefaultCell().setBorder(Rectangle.BOTTOM); for (PdfPCell cell : tableHeader) { cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); } header.writeSelectedRows(0, -1, 60, 803, writer.getDirectContent()); } catch (DocumentException ex) { Logger.getLogger(HeaderFooter.class.getName()).log(Level.SEVERE, null, ex); } PdfPTable footer = new PdfPTable(3); try { footer.setWidths(new int[] { 24, 24, 24 }); footer.setTotalWidth(527); footer.setLockedWidth(true); footer.getDefaultCell().setFixedHeight(20); footer.getDefaultCell().setBorder(Rectangle.BOTTOM); for (PdfPCell cell : tableFooter) { cell.setBorder(Rectangle.NO_BORDER); footer.addCell(cell); } footer.writeSelectedRows(0, -1, 60, 200, writer.getDirectContent()); } catch (DocumentException ex) { Logger.getLogger(HeaderFooter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.xumpy.itext.services.TimeSheet.java
public PdfPTable body(List<Jobs> jobs) throws DocumentException { BigDecimal totalHours = new BigDecimal(0); PdfPTable timesheets = new PdfPTable(5); timesheets.setWidths(new int[] { 25, 20, 10, 10, 48 }); SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy"); PdfPCell header1 = new PdfPCell(new Paragraph("Client")); PdfPCell header2 = new PdfPCell(new Paragraph("Date")); PdfPCell header3 = new PdfPCell(new Paragraph("Hours")); PdfPCell header4 = new PdfPCell(new Paragraph("Perc.")); PdfPCell header5 = new PdfPCell(new Paragraph("Remarks")); timesheets.addCell(header1);//w w w . j av a 2 s . c om timesheets.addCell(header2); timesheets.addCell(header3); timesheets.addCell(header4); timesheets.addCell(header5); for (Jobs job : jobs) { PdfPCell cell1 = new PdfPCell(new Paragraph(job.getJobsGroup().getName())); PdfPCell cell2 = new PdfPCell(new Paragraph(df.format(job.getJobDate()))); PdfPCell cell3 = new PdfPCell(new Paragraph(job.getWorkedHours().toString())); PdfPCell cell4 = new PdfPCell(new Paragraph(" ")); if (job.getPercentage() != null) { cell4 = new PdfPCell(new Paragraph(job.getPercentage().toString())); } PdfPCell cell5 = new PdfPCell(new Paragraph(job.getRemarks())); timesheets.addCell(cell1); timesheets.addCell(cell2); timesheets.addCell(cell3); timesheets.addCell(cell4); timesheets.addCell(cell5); totalHours = totalHours.add(job.getWorkedHours()); } PdfPCell footer1 = new PdfPCell(new Paragraph(" ")); PdfPCell footer2 = new PdfPCell(new Paragraph("Total Hours")); PdfPCell footer3 = new PdfPCell(new Paragraph(totalHours.toString())); PdfPCell footer4 = new PdfPCell(new Paragraph(" ")); PdfPCell footer5 = new PdfPCell(new Paragraph(" ")); PdfPCell footer6 = new PdfPCell(new Paragraph(" ")); PdfPCell footer7 = new PdfPCell(new Paragraph("Total Days")); PdfPCell footer8 = new PdfPCell(new Paragraph(totalHours.divide(new BigDecimal(8)).toString())); PdfPCell footer9 = new PdfPCell(new Paragraph(" ")); PdfPCell footer10 = new PdfPCell(new Paragraph(" ")); timesheets.addCell(footer1); timesheets.addCell(footer2); timesheets.addCell(footer3); timesheets.addCell(footer4); timesheets.addCell(footer5); timesheets.addCell(footer6); timesheets.addCell(footer7); timesheets.addCell(footer8); timesheets.addCell(footer9); timesheets.addCell(footer10); return timesheets; }
From source file:comedor.actions.OperacionesComedorAction.java
private void crearPDF() throws IOException, DocumentException { Restaurante restaurante = godr.obtenerDatosRestaurante(); //Creamos el directorio donde almacenar los pdf sino existe File file = new File(RUTA_CUENTAS); //Especificamos la ruta if (!file.exists()) { //Si el directorio no existe if (file.mkdir()) { //Creamos el directorio //Le asignamos los permisos 777 file.setExecutable(true);//from ww w. jav a2 s .co m file.setReadable(true); file.setExecutable(true); } else { System.err.println("Error al crear el directorio especificado"); throw new IOException(); //Lanzamos una excepcion } } if (file.exists()) { //Si el directorio existe //Creamos el documento Document documento = new Document(); //Creamos el OutputStream para el fichero pdf FileOutputStream destino = new FileOutputStream(RUTA_CUENTAS + nombreDocumento); //Asociamos el FileOutputStream al Document PdfWriter.getInstance(documento, destino); //Abrimos el documento documento.open(); //Aadimos el nombre del restaurante Font titulo = FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLDITALIC); Chunk chunk = new Chunk(restaurante.getNombre(), titulo); Paragraph parrafo = new Paragraph(chunk); parrafo.setAlignment(Element.ALIGN_CENTER); documento.add(parrafo); //Aadimos la imagen String path = request.getServletContext().getRealPath("/img/elvis.png"); Image foto = Image.getInstance(path); foto.scaleToFit(100, 100); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); //Aadimos los datos del restaurante Font datos = FontFactory.getFont(FontFactory.TIMES, 12, Font.NORMAL); chunk = new Chunk(getText("cuenta.cif") + ": " + restaurante.getCif(), datos); documento.add(new Paragraph(chunk)); chunk = new Chunk(getText("cuenta.direccion") + ": " + restaurante.getDireccion(), datos); documento.add(new Paragraph(chunk)); chunk = new Chunk(getText("cuenta.telefono") + ": " + restaurante.getTelefono(), datos); documento.add(new Paragraph(chunk)); //Aadimos los datos de la cuenta chunk = new Chunk(getText("cuenta.cuentaId") + ": " + cuenta.getId(), datos); documento.add(new Paragraph(chunk)); SimpleDateFormat formatoFecha = new SimpleDateFormat("dd-MM-yyyy"); chunk = new Chunk(getText("cuenta.fecha") + ": " + formatoFecha.format(cuenta.getFecha()), datos); documento.add(new Paragraph(chunk)); SimpleDateFormat formtoHora = new SimpleDateFormat("HH:mm:ss"); chunk = new Chunk(getText("cuenta.hora") + ": " + formtoHora.format(cuenta.getFecha()), datos); documento.add(new Paragraph(chunk)); //Aadimos los datos del pedido //Obtenemos el usuario, es decir, del camarero con el nombre que tenemos registrado en la session chunk = new Chunk(getText("cuenta.camarero") + ": " + session.get("usuario").toString(), datos); documento.add(new Paragraph(chunk)); documento.add(new Chunk(Chunk.NEWLINE)); //Salto de linea //Aadimos la tabla con los datos del pedido //Creamos una tabla PdfPTable tabla = new PdfPTable(4); //Especificamos el numero de columnas //Aadimos la cabecera de la tabla tabla.addCell(getText("cuenta.producto")); tabla.addCell(getText("cuenta.unidades")); tabla.addCell(getText("cuenta.pvp")); tabla.addCell(getText("cuenta.total")); for (Producto producto : pedido.getListaProductos()) { tabla.addCell(producto.getNombre()); tabla.addCell(String.valueOf(producto.getUnidades())); tabla.addCell(String.valueOf(producto.getPrecio())); tabla.addCell(String.valueOf(producto.getPrecio() * producto.getUnidades())); if (producto instanceof Hamburguesa) { Hamburguesa h = (Hamburguesa) producto; for (Producto extra : h.getListaProductosExtra()) { tabla.addCell("(E) " + extra.getNombre()); tabla.addCell(String.valueOf(extra.getUnidades())); tabla.addCell(String.valueOf(extra.getPrecio())); tabla.addCell(String.valueOf(extra.getPrecio() * extra.getUnidades())); } } } //Aadimos la tabla al documento documento.add(tabla); documento.add(new Chunk(Chunk.NEWLINE)); //Salto de linea //Aadimos una tabla con los impuestos y el total a pagar tabla = new PdfPTable(3); //Especificamos el numero de columnas tabla.addCell(getText("cuenta.baseImponible") + ": " + pedido.getImporte() + ""); tabla.addCell(""); tabla.addCell(""); DecimalFormat formato = new DecimalFormat("#.##"); for (Impuesto dato : listaImpuestos) { tabla.addCell(""); tabla.addCell(dato.getNombre() + ": " + dato.getValor()); double impuesto = (pedido.getImporte() * dato.getValor()) / 100; tabla.addCell( getText("cuenta.impuesto") + " " + dato.getNombre() + ": " + formato.format(impuesto)); } tabla.addCell(getText("cuenta.total") + ": " + cuenta.getCantidad() + ""); tabla.addCell(""); tabla.addCell(""); //Aadimos la tabla al documento documento.add(tabla); //Cerramos el documento documento.close(); } else { //Si el directoiro no existe System.err.println("OperacionesComedorAction. Error no existe el directorio especificado"); throw new IOException(); //Lanzamos una excepcion } }
From source file:comisionesafis.informes.CintaComisiones.java
public boolean generar() { // Abrimos el fichero de comisiones String sSQL = ""; Statement stmt;/* www .j a va 2 s .c o 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.FacturasComisionesAgentes.java
public boolean generar() { // Abrimos el fichero de comisiones Periodos periodos = new Periodos(pb.getFicheroComisiones()); String sSQL = ""; Statement stmt;/*from www. j a va 2 s. c om*/ ResultSet rsComisiones; String sFactura1; String sFactura2; // 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("FacturasComisionesAgentes.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, salida); writer.setInitialLeading(0); // Obtenemos una instancia de nuestro manejador de eventos FacturasComisionesAgentesPie pie = new FacturasComisionesAgentesPie(); //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); while (rsComisiones.next()) { // Generamos los prrafos // Datos del agente Paragraph pAgente[] = new Paragraph[5]; pAgente[0] = new Paragraph(); pAgente[0].add(rsComisiones.getString("Nombre")); pAgente[0].setAlignment(Paragraph.ALIGN_LEFT); pAgente[1] = new Paragraph(); pAgente[1].add(rsComisiones.getString("Direccion")); pAgente[1].setAlignment(Paragraph.ALIGN_LEFT); pAgente[2] = new Paragraph(); pAgente[2].add(rsComisiones.getString("CodPostal") + " " + rsComisiones.getString("Poblacion")); pAgente[2].setAlignment(Paragraph.ALIGN_LEFT); pAgente[3] = new Paragraph(); pAgente[3].add(rsComisiones.getString("Provincia")); pAgente[3].setAlignment(Paragraph.ALIGN_LEFT); pAgente[4] = new Paragraph(); pAgente[4].add(rsComisiones.getString("NIF")); pAgente[4].setAlignment(Paragraph.ALIGN_LEFT); // creating separators LineSeparator separador = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -2); // Datos fijos Paragraph pPelayo[] = new Paragraph[5]; pPelayo[0] = new Paragraph(); pPelayo[0].add("PELAYO VIDA"); pPelayo[0].setAlignment(Paragraph.ALIGN_RIGHT); pPelayo[1] = new Paragraph(); pPelayo[1].add("CL SANTA ENGRACIA 69"); pPelayo[1].setAlignment(Paragraph.ALIGN_RIGHT); pPelayo[2] = new Paragraph(); pPelayo[2].add("28010 MADRID"); pPelayo[2].setAlignment(Paragraph.ALIGN_RIGHT); pPelayo[3] = new Paragraph(); pPelayo[3].add("MADRID"); pPelayo[3].setAlignment(Paragraph.ALIGN_RIGHT); pPelayo[4] = new Paragraph(); pPelayo[4].add("06422"); pPelayo[4].setAlignment(Paragraph.ALIGN_RIGHT); // Fecha Paragraph pFecha = new Paragraph(); pFecha = new Paragraph("Madrid, a " + periodos.extraeFechaLarga()); pFecha.setAlignment(Paragraph.ALIGN_RIGHT); // Lnea 1 de FACTURA Paragraph pFactura1 = new Paragraph(); sFactura1 = "FACTURA: n factura "; sFactura1 += rsComisiones.getString("CodAgente") + " - "; sFactura1 += periodos.extraePeriodoMY("MM-YYYY"); pFactura1 = new Paragraph(sFactura1); // Lnea 2 de FACTURA Paragraph pFactura2 = new Paragraph(); sFactura2 = "Factura por la prestacin de servicios relativos a las operaciones "; sFactura2 += "de intermediacin de seguros realizadas para su entidad del mes de "; sFactura2 += periodos.extraePeriodoMY("MM YYYY"); ; pFactura2 = new Paragraph(sFactura2); // Datos Econmicos float[] anchuras = { 5f, 2f }; PdfPTable table = new PdfPTable(anchuras); table.getDefaultCell().setBorder(0); // Tipo de letra para la tabla Font font = new Font(Font.FontFamily.COURIER, 11, Font.NORMAL); PdfPCell celda = new PdfPCell(); celda = new PdfPCell(new Phrase("Comisiones pagadas", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); celda = new PdfPCell( new Phrase(Double.toString(rsComisiones.getDouble("TotalComisiones")) + " ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase("Otros conceptos", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); celda = new PdfPCell(new Phrase(" ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase( "Retencin (" + Double.toString(rsComisiones.getDouble("RetencionPorcentaje")) + "%)", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); Double dblRetencion = rsComisiones.getDouble("TotalComisiones") * (rsComisiones.getDouble("RetencionPorcentaje") / 100); celda = new PdfPCell(new Phrase(Numeros.formateaDosDecimales(dblRetencion) + " ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase("Conceptos no sujetos", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); celda = new PdfPCell(new Phrase(" ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase("Total a pagar", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); Double dblTotalPagar = rsComisiones.getDouble("TotalComisiones") - dblRetencion; celda = new PdfPCell(new Phrase(Numeros.formateaDosDecimales(dblTotalPagar) + " ", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); // Literal: Operacin exenta de IVA Paragraph pColetilla = new Paragraph(); pColetilla.add("Operacin exenta de IVA"); // Aadimos los prrafos al Documento for (int i = 0; i < 5; i++) documento.add(pAgente[i]); documento.add(new Paragraph(" ")); documento.add(separador); for (int i = 0; i < 5; i++) documento.add(pPelayo[i]); documento.add(new Paragraph(" ")); documento.add(pFecha); documento.add(new Paragraph(" ")); documento.add(pFactura1); documento.add(separador); documento.add(pFactura2); // Agregamos la tabla al documento documento.add(new Paragraph(" ")); documento.add(table); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(pColetilla); documento.newPage(); } documento.close(); return true; } catch (Exception e) { return false; } }
From source file:comisionesafis.informes.LiquidacionComisiones.java
private void printCabecera2(Document documento, ResultSet rsAgentes) { String sSQL = ""; Statement stmt;/*from w w w . ja va 2 s . co m*/ ResultSet rsDatosAgente; try { // SELECT para extraer todos los cdigos de los agentes con Recibos sSQL = "SELECT * "; sSQL += " FROM Agentes"; sSQL += " WHERE CodAgente='" + rsAgentes.getString("Agente") + "'"; stmt = conexion.createStatement(); rsDatosAgente = stmt.executeQuery(sSQL); if (!rsDatosAgente.next()) { // Este error no debera darse System.out.println("Error: No hay datos para el agente " + rsAgentes.getString("Agente")); return; } // Generamos la cabecera //Font fuenteCabecera = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL); float[] anchuras = { 3f, 1f, 5f }; PdfPTable table1 = new PdfPTable(anchuras); // Tipo de letra para la tabla Font font = new Font(Font.FontFamily.COURIER, 9, Font.NORMAL); PdfPCell celda = new PdfPCell(); // Sucursal/Delegacin celda = new PdfPCell(new Phrase("SUCURSAL/DELEGACIN", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(celda); celda = new PdfPCell(new Phrase("02", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(celda); celda = new PdfPCell(new Phrase("PELAYO MONDIALE VIDA", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(celda); // No tenemos estos datos. Me pide Fernando que los quite // // Inspeccin // celda = new PdfPCell(new Phrase("INSPECCIN",font)); // celda.setBorder(Rectangle.NO_BORDER); // celda.setHorizontalAlignment(Element.ALIGN_LEFT); // table1.addCell(celda); // // celda = new PdfPCell(new Phrase("000001",font)); // celda.setBorder(Rectangle.NO_BORDER); // celda.setHorizontalAlignment(Element.ALIGN_LEFT); // table1.addCell(celda); // // celda = new PdfPCell(new Phrase("ACUERDO DE DISTRIBUCIN",font)); // celda.setBorder(Rectangle.NO_BORDER); // celda.setHorizontalAlignment(Element.ALIGN_LEFT); // table1.addCell(celda); // Agente celda = new PdfPCell(new Phrase("AGENTE", font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(celda); celda = new PdfPCell(new Phrase(rsDatosAgente.getString("CodAgente"), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(celda); celda = new PdfPCell(new Phrase(rsDatosAgente.getString("Nombre"), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(celda); documento.add(table1); } catch (Exception e) { System.out.println(e.getMessage()); } }