0

Is there a way to convert the outputstream to base64outputstream, everything works except for the last part in which I don't get anything, neither log nor error, just a blank screen when executed. It is supposed that with this the report should be downloaded in pdf format when pressing generate report in the jsp page.

 //THIS IS A SERVLET
        private void report(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JRException {
            try {
            //LIST FROM DATABASE MYSQL
            List<Bienes> data = servicio.generarReporte();
            //LIST TO JRBEANCOLLECTION AS DATASOURCE FOR REPORT
            JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(data);
            //REPORT JASPER
            String file = request.getServletContext().getRealPath("/webapp/ReporteBienes.jasper");
            FileInputStream stream = new FileInputStream(new File(file));
            //PARAMETERS (nothing for now)
            Map<String,Object> params = new HashMap<String,Object>();
            JasperReport jasperReport = (JasperReport) JRLoader.loadObject(stream);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
            response.setContentType("application/x-pdf");
            response.addHeader("content-disposition","attachment;filename=ReporteBienes.pdf");
            //HERE IS THE PROBLEM: Type missmatch: cannot convert from ServletOutputStream to Base64.OutputStream
            OutputStream outStream = response.getOutputStream();        
//exportReportToPdfStream(JasperPrint jasperPrint, OutputStream outputStream)
//does not accept Servletoutputstream and I get a blank screen for it
            JasperExportManager.exportReportToPdfStream(jasperPrint, outStream);
            }
            
            catch(Exception e) {
                e.printStackTrace();
            }
        }
  • you could use a ByteArrayOutputStream instead of outStream and then convert the ByteArray to Base64 output. https://stackoverflow.com/questions/42667942/convert-inputstream-to-base64-string , https://stackoverflow.com/questions/5778658/how-to-convert-outputstream-to-inputstream or use Base64OutputStream https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64OutputStream.html – Roshan Jun 28 '22 at 19:13
  • 1
    I'm confused - what does a goal of achieving pdf download have to do with base64? – g00se Jun 28 '22 at 21:12

0 Answers0