Java - Guardar un reporte en formato pdf

 
Vista:

Guardar un reporte en formato pdf

Publicado por Paulinas (4 intervenciones) el 27/08/2015 00:51:49
Hola si me podrian ayudar con un reporte se abre correctamente el reporte al ejecutar la aplicacion, pero deseo guardarlo en formato pdf ... y se me guarda como un html este es mi codigo;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public void reporte_calificaciones(String calificacion) {
 
        try {
 
            listadatoscalificacion = DatosCalificacionAcciones.Obtener_calificaciones(ocatevc.getIdcategoria(), calificacion, fechadesde, fechahasta, objperfil, dm.getSesionFuncionActual());
            // listadatoscalificacion = DatosCalificacionAcciones.Obtener_calificaciones(128, calificacion, fechadesde, fechahasta);
            Reporte datasource = new Reporte();
            if (!listadatoscalificacion.isEmpty()) {
                for (DatosCalificacion datevc : listadatoscalificacion) {
                    Dato d = new Dato(
                            datevc.getIdticket(),
                            PerfilServicios.ObtenerPerfilDadoCodigo(datevc.getIdcreador(), dm.getSesionPerfilActual(), dm.getSesionFuncionActual()).getStralias(),
                            datevc.getAsunto(),
                            datevc.getSolucion(),
                            datevc.getFecha_llegada(),
                            datevc.getHora_llegada(),
                            datevc.getFecha_solucion(),
                            datevc.getHora_solucion(),
                            datevc.getCalificacion()
                    );
 
                    datasource.addParticipante(d);
                }
                JasperReport reporte = (JasperReport) JRLoader.loadObject(Metodos_Reportes.getAbsolutePath("report1.jasper"));
                JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, null, datasource);
                HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
                ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
                JRExporter exporter = new JRPdfExporter();
                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);
                exporter.exportReport();
            } else {
                Util.addErrorMessage("No tiene evaluaciones de este tipo");
            }
 
        } catch (Exception e) {
        }
 
    }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alberto
Val: 308
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Guardar un reporte en formato pdf

Publicado por Alberto (303 intervenciones) el 27/08/2015 01:17:39
Hola...

Intenta cambiar la siguiente línea de tu código...

1
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);

Por la siguiente línea...

1
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,new FileOutputStream("C:\\Quality\\Desktop\\Reporte.pdf"));

Por defecto las salidas con IReport son archivos HTML, sin embargo, nosotros podemos cambiar el tipo de salida tal y como puedes ver en el ejemplo. Lo único que necesitamos es realizar una instancia a FileOutputStream el cual nos permitirá escribir datos a un archivo, por ejemplo: PDF.

http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html

Cualquier duda y/o inconveniente, aquí estamos. Suerte!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar