1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
   |  File file = new File("c:/");
            File reportFile = new File(file, path );
            if (!reportFile.exists())
				throw new JRRuntimeException("File "+path+".jasper not found. The report design must be compiled first.");
            else{     
            byte[] bytes = JasperRunManager.runReportToPdf(jasperReport, new HashMap(), connection);*/
 
            FacesContext context = FacesContext.getCurrentInstance();
            HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
            //Definition du header et contenType avant la génération PDF
            response.setContentType("application/pdf");
            response.setHeader("Content-disposition", "inline");
 
            byte[] bytes = JasperRunManager.runReportToPdf(new FileInputStream(reportFile), new HashMap(), connection);
            System.out.println("/ bytes == "+bytes);
            System.out.println("/ bytes.length == "+bytes.length);
            response.addHeader("Content-disposition","attachment;filename=rapport.pdf");
            response.setContentLength(bytes.length);
            response.getOutputStream().write(bytes);
            response.setContentType("application/pdf");
            context.responseComplete();
 
            } | 
Partager