List of usage examples for com.itextpdf.text.pdf PdfWriter setPageEvent
public void setPageEvent(final PdfPageEvent event)
PdfPageEvent
for this document. From source file:com.softwaremagico.tm.pdf.small.SmallCharacterSheet.java
License:Open Source License
@Override protected void addDocumentWriterEvents(PdfWriter writer) { writer.setPageEvent(new SheetBackgroundEvent()); }
From source file:com.softwaremagico.tm.pdf.small.SmallPartySheet.java
License:Open Source License
@Override protected void addEvent(PdfWriter writer) { writer.setPageEvent(new PartyFooterEvent(party, -15)); }
From source file:com.systemevent.jsfclass.util.PdfEvento.java
public void imprimirPdf(Evento events) { Evento event = events;//w w w .ja v a 2 s .co m //buscarPDF(n); try { //Generamos el archivo PDF String directorioArchivos; ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); directorioArchivos = ctx.getRealPath("\'") + "reports"; String name = directorioArchivos + "\'document-report.pdf"; //String name="C:\\Users\\Jose_Gascon\\Documents\\NetBeansProjects\\SystemEvent\\target\\SystemEvent-1.0-SNAPSHOT\\reports\\document-report.pdf"; Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(name)); FormatoPDF encabezado = new FormatoPDF(""); Paragraph parrafo, datos, datos1; int i; // indicamos que objecto manejara los eventos al escribir el Pdf writer.setPageEvent(encabezado); document.open(); document.addAuthor("Erick Ramirez"); document.addTitle("Reporte"); //Creamos una cantidad significativa de paginas para probar el encabezado //for (i = 0; i < 4; i++) { parrafo = new Paragraph("Presupuesto de Evento"); parrafo.setAlignment(Element.ALIGN_CENTER); document.add(parrafo); // document.newPage(); //} datos = new Paragraph("Ubicacion: " + event.getUbicacion()); datos1 = new Paragraph("Pais: " + event.getCodigoPais().getNombre()); datos.setAlignment(Element.ALIGN_RIGHT); datos1.setAlignment(Element.ALIGN_RIGHT); document.add(datos1); document.add(datos); document.add(new Paragraph("")); document.add(new Paragraph("")); document.add(new Paragraph("")); document.add(new Paragraph("")); // PdfPTable table = new PdfPTable(2); // // table.addCell("Cliente: "); // table.addCell(event.getIdCliente().getNombre()); // // table.addCell("Descripcion del Evento: "); // table.addCell(event.getDescripcion()); // // document.add(table); document.add(Tabla_compleja()); document.close(); //---------------------------- //Abrimos el archivo PDF FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "inline=filename=" + name); try { response.getOutputStream().write(Util.getBytesFromFile(new File(name))); response.getOutputStream().flush(); response.getOutputStream().close(); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.vectorprint.report.itext.TocOutputStream.java
License:Open Source License
@Override public void secondPass(InputStream firstPass, OutputStream orig) throws IOException { PdfReader reader = null;//from w ww . j a va 2 s. c o m VectorPrintDocument vpd = (VectorPrintDocument) outer.getDocument(); try { reader = new PdfReader(firstPass); prepareToc(); // init fresh components for second pass styling StylerFactory _stylerFactory = outer.getStylerFactory().getClass().newInstance(); StylerFactoryHelper.SETTINGS_ANNOTATION_PROCESSOR.initSettings(_stylerFactory, outer.getSettings()); _stylerFactory.setLayerManager(outer.getElementProducer()); _stylerFactory.setImageLoader(outer.getElementProducer()); outer.getStyleHelper().setStylerFactory(_stylerFactory); EventHelper event = outer.getEventHelper().getClass().newInstance(); event.setItextStylerFactory(_stylerFactory); event.setElementProvider(outer.getElementProducer()); ((DefaultElementProducer) outer.getElementProducer()).setPh(event); Document d = new VectorPrintDocument(event, _stylerFactory, outer.getStyleHelper()); PdfWriter w = PdfWriter.getInstance(d, orig); w.setPageEvent(event); outer.getStyleHelper().setVpd((VectorPrintDocument) d); _stylerFactory.setDocument(d, w); DocumentStyler ds = _stylerFactory.getDocumentStyler(); outer.getStyleHelper().style(d, null, StyleHelper.toCollection(ds)); d.open(); ds.styleAfterOpen(d, null); List outline = SimpleBookmark.getBookmark(reader); if (!ds.getValue(DocumentSettings.TOCAPPEND, Boolean.class)) { printToc(d, w, vpd); if (outline != null) { int cur = w.getCurrentPageNumber(); SimpleBookmark.shiftPageNumbers(outline, cur, null); } d.newPage(); } outer.getSettings().put(ReportConstants.DEBUG, Boolean.FALSE.toString()); for (int p = 1; p <= reader.getNumberOfPages(); p++) { Image page = Image.getInstance(w.getImportedPage(reader, p)); page.setAbsolutePosition(0, 0); d.setPageSize(page); d.newPage(); Chunk i = new Chunk(" "); if (vpd.getToc().containsKey(p)) { Section s = null; for (Map.Entry<Integer, List<Section>> e : vpd.getToc().entrySet()) { if (e.getKey() == p) { s = e.getValue().get(0); break; } } i.setLocalDestination(s.getTitle().getContent()); } d.add(i); w.getDirectContent().addImage(page); w.freeReader(reader); } if (_stylerFactory.getDocumentStyler().getValue(DocumentSettings.TOCAPPEND, Boolean.class)) { printToc(d, w, vpd); } w.setOutlines(outline); if (outer.isWasDebug()) { event.setLastPage(outer.getWriter().getCurrentPageNumber()); d.setPageSize(new Rectangle(ItextHelper.mmToPts(297), ItextHelper.mmToPts(210))); d.setMargins(5, 5, 5, 5); d.newPage(); outer.getSettings().put(ReportConstants.DEBUG, Boolean.TRUE.toString()); event.setDebugHereAfter(true); DebugHelper.appendDebugInfo(w, d, outer.getSettings(), _stylerFactory); } d.close(); } catch (VectorPrintException | DocumentException | InstantiationException | IllegalAccessException ex) { throw new VectorPrintRuntimeException(ex); } finally { if (reader != null) { reader.close(); } } }
From source file:com.vectorprint.vectorprintreportgui.Controller.java
License:Open Source License
private void importStyle(ParsingProperties settings) throws DocumentException, VectorPrintException { clear(null);//from www.ja v a 2 s . c o m Boolean preAndPost = settings.getBooleanProperty(true, DefaultStylerFactory.PREANDPOSTSTYLE); // set to false when importing to prevent all pre and post stylers to be added to regulerar style classes settings.put(DefaultStylerFactory.PREANDPOSTSTYLE, Boolean.FALSE.toString()); DefaultStylerFactory sf = new DefaultStylerFactory(); StylerFactoryHelper.SETTINGS_ANNOTATION_PROCESSOR.initSettings(sf, settings); Document d = new Document(); PdfWriter w = PdfWriter.getInstance(d, new ByteArrayOutputStream(0)); w.setPageEvent(new EventHelper()); sf.setDocument(d, w); for (Map.Entry<String, String[]> e : settings.entrySet()) { commentsBefore.put(e.getKey(), settings.getCommentBeforeKey(e.getKey())); if (ReportConstants.DOCUMENTSETTINGS.equals(e.getKey())) { stylingConfig.put(e.getKey(), new ArrayList<>(1)); stylingConfig.get(e.getKey()).add(sf.getDocumentStyler()); pdf1a.setSelected(sf.getDocumentStyler().getValue(DocumentSettings.PDFA, Boolean.class)); toc.setSelected(sf.getDocumentStyler().getValue(DocumentSettings.TOC, Boolean.class)); } else if (ViewHelper.isStyler(e.getKey(), settings)) { stylingConfig.put(e.getKey(), new ArrayList<>(3)); try { List<BaseStyler> l = sf.getStylers(e.getKey()); stylingConfig.get(e.getKey()).addAll(l); getConditions(l); getDefaults(l, settings); } catch (VectorPrintException ex) { ViewHelper.toError(ex, error); } } else if (!ViewHelper.isCondition(e.getKey(), settings)) { if (DefaultStylerFactory.PREANDPOSTSTYLE.equals(e.getKey())) { prepost.setSelected(preAndPost); extraSettings.put(e.getKey(), preAndPost.toString()); } else { if (ReportConstants.DEBUG.equals(e.getKey())) { debug.setSelected(Boolean.valueOf(e.getValue()[0])); } else if (ReportConstants.PRINTFOOTER.equals(e.getKey())) { footer.setSelected(Boolean.valueOf(e.getValue()[0])); } extraSettings.put(e.getKey(), e.getValue()[0]); } } } for (Iterator it = extraSettings.entrySet().iterator(); it.hasNext();) { Map.Entry<String, String> e = (Map.Entry<String, String>) it.next(); if (processed.contains(e.getKey())) { it.remove(); } } // check conditions not referenced settings.entrySet().stream().forEach((e) -> { if (ViewHelper.isCondition(e.getKey(), settings)) { Logger.getLogger(Controller.class.getName()) .warning(String.format("unreferenced conditions for key: %s", e.getKey())); List<StylingCondition> conditions; try { conditions = sf.getConditions(e.getKey()); } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } stylingConfig.put(e.getKey(), new ArrayList<>(conditions.size())); stylingConfig.get(e.getKey()).addAll(conditions); } }); commentsAfter.addAll(settings.getTrailingComment()); ViewHelper.notify("ok", "import complete", "you can now adapt and (re)build your stylesheet"); }
From source file:com.xumpy.itext.services.TimeSheet.java
public OutputStream pdf(List<Jobs> jobs, OutputStream outputStream) throws DocumentException, BadElementException, IOException, URISyntaxException { Document document = new Document(PageSize.A4, 0, 0, 160, 220); PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open();/*from ww w .ja va 2s . c o m*/ HeaderFooter event = new HeaderFooter(); event.setTableHeader(header()); event.setTableFooter(footer()); writer.setPageEvent(event); document.add(body(jobs)); document.close(); return outputStream; }
From source file:comisionesafis.informes.CintaComisiones.java
public boolean generar() { // Abrimos el fichero de comisiones String sSQL = ""; Statement stmt;//from ww w. j a v a 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 ww w . ja v a2s .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
public boolean generar() { // Abrimos el fichero de comisiones String sSQL = ""; Statement stmt;/* w w w . j ava 2 s. c o m*/ ResultSet rsAgentes; ResultSet rsRecibos; PdfPCell celda; boolean cabeceraColumnas; int filasPorPagina = 0; int fila = 0; PdfPTable table; Double dblTotal = 0.0; // 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("LiquidacionComisiones.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, salida); writer.setInitialLeading(0); // Obtenemos una instancia de nuestro manejador de eventos LiquidacionComisionesPie pie = new LiquidacionComisionesPie(); //Asignamos el manejador de eventos al escritor. writer.setPageEvent(pie); // Abrimos el Documento documento.open(); // SELECT para extraer todos los cdigos de los agentes con Recibos sSQL = "SELECT DISTINCT (CodAgente) AS Agente "; sSQL += " FROM ResumenComisiones"; sSQL += " ORDER BY CodAgente"; stmt = conexion.createStatement(); rsAgentes = stmt.executeQuery(sSQL); while (rsAgentes.next()) { if (sumaComisiones(rsAgentes.getString("Agente")) != 0) { paginaNum = 0; printCabecera1(documento); printCabeceraPelayo(documento); printCabecera2(documento, rsAgentes); // SELECT para extraer todos los Recibos de un agente sSQL = "SELECT * "; sSQL += " FROM Recibos"; sSQL += " WHERE CodAgente = '" + rsAgentes.getString("Agente") + "'"; stmt = conexion.createStatement(); rsRecibos = stmt.executeQuery(sSQL); // if(rsAgentes.getString("Agente").equals("10803")){ // System.out.println(""); // } // Creamos la tabla formateada table = creaTabla(); cabeceraColumnas = true; filasPorPagina = 42; dblTotal = 0.0; while (rsRecibos.next()) { if (Double.parseDouble(rsRecibos.getString("ImpComision")) != 0) { if (fila >= filasPorPagina) { // Salto de pgina // Imprimimos el contenido de la tabla documento.add(table); documento.newPage(); table = creaTabla(); saltoDePagina(documento, table, rsAgentes); fila = 1; filasPorPagina = 47; } else if (cabeceraColumnas) { // Primera pgina printCabeceraColumnas(table); cabeceraColumnas = false; fila = 1; } Font font = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL); celda = new PdfPCell(new Phrase(rsRecibos.getString("NPoliza"), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); celda = new PdfPCell( new Phrase(Fechas.fechaVencimiento(rsRecibos.getString("Fecha")), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); celda = new PdfPCell(new Phrase(fondoRecibo(rsRecibos.getString("Descripcion")), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(celda); celda = new PdfPCell(new Phrase(rsRecibos.getString("Importe"), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); celda = new PdfPCell(new Phrase(Numeros.formateaDosDecimales( Double.parseDouble(rsRecibos.getString("ImpComision"))), font)); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celda); dblTotal += Double.parseDouble(rsRecibos.getString("ImpComision")); fila++; } } if (fila >= filasPorPagina - 5) { documento.add(table); documento.newPage(); table = creaTabla(); } printResumenContable(table, dblTotal, rsAgentes.getString("Agente")); documento.add(table); documento.newPage(); } } documento.close(); return true; } catch (Exception e) { return false; } }
From source file:contabilidad.Capital.java
public Capital() { jFrame = new JFrame("Capital"); jFrame.setDefaultCloseOperation(jFrame.DISPOSE_ON_CLOSE); jFrame.setSize(800, 600);/*from w ww.j a v a 2s.c o m*/ jFrame.setLocationRelativeTo(null); jFrame.setIconImage(new ImageIcon(getClass().getResource("../imagenes/rana.jpg")).getImage()); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); System.out.println("X:" + screenSize.width + " Y:" + screenSize.height); int x = (screenSize.width / 2) - (jFrame.getSize().width / 2); int y = (screenSize.height / 2) - (jFrame.getSize().height / 2); jFrame.setLocation(x, y); JPanel jPanel = new JPanel(); jPanel.setLayout(null); JLabel capitalC = new JLabel("Capital Social: "); capitalC.setBounds(50, 90, 90, 20); jPanel.add(capitalC); JLabel cs = new JLabel("5000"); cs.setBounds(140, 90, 90, 20); jPanel.add(cs); JLabel resultado = new JLabel("Resultado de ejercicio: "); resultado.setBounds(100, 130, 150, 20); jPanel.add(resultado); JLabel er = new JLabel("prueba"); er.setBounds(250, 130, 90, 20); jPanel.add(er); JLabel capitalCT = new JLabel("Total Capital: "); capitalCT.setBounds(170, 170, 90, 20); jPanel.add(capitalCT); JLabel toc = new JLabel("prueba"); toc.setBounds(270, 170, 90, 20); jPanel.add(toc); JMenuBar jMenuBar = new JMenuBar(); JMenu jMenu = new JMenu("Inicio"); JMenu jMenu2 = new JMenu("Reportes"); JMenu jMenu3 = new JMenu("Ayuda"); jMenuBar.add(jMenu); jMenuBar.add(jMenu2); jMenuBar.add(jMenu3); JMenuItem jMenuItem2 = new JMenuItem("Reporte PDF"); jMenuItem2.addActionListener(new MenuListener(jFrame)); jMenuItem2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selecto = new JFileChooser(); int op = selecto.showSaveDialog(null); if (op == JFileChooser.APPROVE_OPTION) { try { OutputStream archivo = new FileOutputStream(selecto.getSelectedFile() + ".pdf"); Document document = new Document(); document.addAuthor("Contabilidad"); document.addTitle("Capital"); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(selecto.getSelectedFile() + ".pdf")); writer.setInitialLeading(16); Rectangle rct = new Rectangle(80, 104, 500, 688); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); document.add(new Paragraph("Capital")); document.add(new Paragraph(" ")); Paragraph parrafo3 = new Paragraph("Fecha: 25/5/42"); parrafo3.setAlignment(2);//el 1 es para centrar document.add(parrafo3); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); Paragraph parrafo2 = new Paragraph("Capital Social : 5000 "); parrafo2.setAlignment(6);//el 1 es para centrar document.add(parrafo2); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); Paragraph parrafo5 = new Paragraph("Estado de resultados: "); parrafo5.setAlignment(6);//el 1 es para centrar document.add(parrafo5); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.close(); archivo.close(); Runtime.getRuntime().exec("cmd /c start " + selecto.getSelectedFile() + ".pdf"); } catch (FileNotFoundException ex) { Logger.getLogger(Capital.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Capital.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Capital.class.getName()).log(Level.SEVERE, null, ex); } } } }); JMenuItem jMenuItem3 = new JMenuItem("Salir"); jMenuItem3.addActionListener(new MenuListener(jFrame)); jMenuItem3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { VentanaGeneral es = new VentanaGeneral(); jFrame.dispose(); } }); JMenuItem jMenuItem7 = new JMenuItem("Acerca de"); jMenuItem7.addActionListener(new MenuListener(jFrame)); jMenu.add(jMenuItem3); jMenu2.add(jMenuItem2); jMenu3.add(jMenuItem7); jFrame.setJMenuBar(jMenuBar); JButton botonac = new JButton("Aceptar"); botonac.setBounds(300, 300, 150, 30); botonac.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Reportes es = new Reportes(); jFrame.dispose(); } }); jPanel.add(botonac); jFrame.add(jPanel); jFrame.setVisible(true); }