Foros del Web » Programación para mayores de 30 ;) » Java »

[SOLUCIONADO] Reportes Itext pasando parametros

Estas en el tema de Reportes Itext pasando parametros en el foro de Java en Foros del Web. Hola a todos, estoy realizando un sistema web con JSF, hibernate y Spring, bueno estoy en la parte de reportes, estoy probando con Itext para ...
  #1 (permalink)  
Antiguo 13/04/2015, 11:24
 
Fecha de Ingreso: diciembre-2014
Ubicación: Lima
Mensajes: 68
Antigüedad: 9 años, 4 meses
Puntos: 0
Reportes Itext pasando parametros

Hola a todos, estoy realizando un sistema web con JSF, hibernate y Spring, bueno estoy en la parte de reportes, estoy probando con Itext para mostrar listados como clientes, articulos, proveedores, etc.
Esto lo logro con esta lineas.

Código Java:
Ver original
  1. public void imprimir(){
  2.         Document document = new Document(PageSize.LETTER);
  3.         try {
  4.             PdfWriter.getInstance(document, baos);
  5.             ArticuloServiceDao articuloServiceDao = new ArticuloServiceDaoImpl();
  6.             List<Articulo> articulos = articuloServiceDao.listado();
  7.             document.open();
  8.            
  9.             Paragraph titulo = new Paragraph("Valois & Plasticos \n",FontFactory.getFont("Times-Roman",35,Font.BOLD,Color.BLACK));
  10.             titulo.setAlignment(Element.ALIGN_CENTER);
  11.             Paragraph stitulo = new Paragraph("Listado de Articulos \n\n",FontFactory.getFont("Times-Roman",15,Font.BOLD,Color.BLACK));
  12.             stitulo.setAlignment(Element.ALIGN_CENTER);
  13.             document.add(new Paragraph(titulo));
  14.             document.add(new Paragraph(stitulo));
  15.             PdfPTable table = new PdfPTable(5);
  16.             table.setTotalWidth(new float[]{30, 350, 90,50,40});
  17.             table.setLockedWidth(true);
  18.            
  19.             PdfPCell cell = new PdfPCell(new Paragraph("Articulo \n",
  20.                     FontFactory.getFont("Arial", 10, Font.BOLD, Color.WHITE)));
  21.             cell.setHorizontalAlignment(Element.ALIGN_CENTER);
  22.             cell.setBackgroundColor(Color.lightGray);
  23.             cell.setColspan(5);
  24. //          table.addCell(cell);
  25.            
  26.             cell = new PdfPCell(new Paragraph("ID",FontFactory.getFont("arial", 6, Font.BOLD, Color.GRAY)));
  27.             table.addCell("Id.");
  28.             table.addCell("Descripcion");
  29.             table.addCell("Rubro");
  30.             table.addCell("Precio");
  31.             table.addCell("Stock");
  32.            
  33.             for (int i = 0; i < articulos.size(); i++) {
  34.                 Articulo a = articulos.get(i);
  35.                 table.addCell(String.valueOf(a.getArtCodigo()));
  36.                 table.addCell(a.getArtDescripcion());
  37.                 table.addCell(a.getRubro().getRubNombre());
  38.                 table.addCell(String.valueOf(a.getArtEfectivo()));
  39.                 table.addCell(String.valueOf(a.getArtStock()));
  40.             }
  41.             document.add(table);
  42.         } catch (Exception e) {
  43.             System.out.println("Error:");
  44.             System.out.println("Error " + e.getMessage());
  45.         }
  46.         document.close();
  47.         FacesContext context = FacesContext.getCurrentInstance();
  48.         Object response = context.getExternalContext().getResponse();
  49.         if (response instanceof HttpServletResponse) {
  50.              
  51.             HttpServletResponse hsr = (HttpServletResponse) response;
  52.             hsr.setContentType("application/pdf");
  53.             hsr.setHeader("Content-disposition", "attachment" );
  54.             hsr.setContentLength(baos.size());
  55.             try {
  56.                 ServletOutputStream out = hsr.getOutputStream();
  57.                 baos.writeTo(out);
  58.                 out.flush();
  59.             } catch (IOException e) {
  60.                 System.out.println("Error:  " + e.getMessage());
  61.             }
  62.             context.responseComplete();
  63.         }              
  64.     }

Esto solo me funciona con firefox, no con chrome.

Ahora quiero realizar un reporte de factura, pero para eso debo mandar un parametro que seria el nro De Factura, pero no encuentro nada en internet que me ayude hacer eso.
Espero una pronta respuesta.

Trabajando con iText, no me convence del todo que cuando trabajaba con iReport, donde yo mismo realizaba el diseño ademas de exportar a pdf al mismo tiempo, cual es recomendable en reportes para jsf.

Mientras tanto revisare un poco de documentacion de apache poi.
  #2 (permalink)  
Antiguo 27/04/2015, 13:08
 
Fecha de Ingreso: diciembre-2014
Ubicación: Lima
Mensajes: 68
Antigüedad: 9 años, 4 meses
Puntos: 0
Respuesta: Reportes Itext pasando parametros

Bueno al final pude realizarlo, tema solucionado...

Etiquetas: jsf
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:42.