Jump to content
We've recently updated our Privacy Statement, available here ×

How To convert to byte array


rldndvv

Recommended Posts

Hi, 

I am using iReport 5.6

When outputting ireport, I want to save the pdf as a byte array

How to convert to byte array when generating report

Below is my source

 @RequestMapping(value = "/jasper/{reportName}/{reportFormat}")    public ModelAndView report(@PathVariable("reportName") String psReportName, @PathVariable("reportFormat") String psReportFormat,            HttpServletRequest poRequest, HttpServletResponse poResponse, Class<?> String) throws IOException {        ModelAndView modelAndView = null;        // User Session Verification        UserSession oLoginUser = (UserSession) SessionUtils.getLoginUser();        if (oLoginUser == null) {            modelAndView = new ModelAndView("common/xls-down-result");            modelAndView.addObject("result", "error_session");            return modelAndView;        }        // Save reporter parameters        Map<String, Object> mParam = new HashMap<String, Object>();        @SuppressWarnings("unchecked")        Enumeration<String> sParamNameList = poRequest.getParameterNames();        while(sParamNameList.hasMoreElements()) {        String sParamName = sParamNameList.nextElement();        // Parameter        mParam.put(sParamName.toUpperCase(), poRequest.getParameter(sParamName));        }        // Save report path        String sJrxmlPath = ctx.getRealPath("") + JASPER_PATH;        mParam.put("JASPER_PATH", sJrxmlPath);        // Report generation        Connection oConnection = DataSourceUtils.getConnection(dataSource);        ServletOutputStream oOuputStream = null;        SimpleOutputStreamExporterOutput oExporterOutput = null;        try {            DefaultJasperReportsContext oReportsContext = DefaultJasperReportsContext.getInstance();            JRPropertiesUtil.getInstance(oReportsContext).setProperty(JRFont.DEFAULT_PDF_ENCODING, "utf-8");            JasperReport oJasperReport = JasperCompileManager.compileReport(sJrxmlPath + psReportName + ".jrxml");            // Data dynamic bind            JasperPrint oJasperPrint = JasperFillManager.fillReport(oJasperReport, mParam, oConnection);            // Jasper Viewer Popup//             JasperViewer.viewReport(oJasperPrint);            // RESPONSE Header            StringBuffer sContentDisposition = new StringBuffer();            sContentDisposition.append("inline;fileName="");            sContentDisposition.append(URLEncoder.encode(psReportName, "UTF-8").replaceAll("\+", "%20"));            sContentDisposition.append("_");            sContentDisposition.append(DateUtil.currentTimeToString(DateUtil.SDF_YYYYMMDDHHMM));            sContentDisposition.append("." + psReportFormat);            sContentDisposition.append("";");            poResponse.setHeader("Content-Disposition", sContentDisposition.toString());            SimpleExporterInput oExporterInput = new SimpleExporterInput(oJasperPrint);            oOuputStream = poResponse.getOutputStream();            oExporterOutput = new SimpleOutputStreamExporterOutput(oOuputStream);            // PDF            poResponse.setContentType("application/pdf");            SimplePdfReportConfiguration oReportConfiguration = new SimplePdfReportConfiguration();            JRPdfExporter oPdfExporter = new JRPdfExporter();            oPdfExporter.setExporterInput(oExporterInput);            oPdfExporter.setExporterOutput(oExporterOutput);            oPdfExporter.setConfiguration(oReportConfiguration);            oPdfExporter.exportReport();                        oOuputStream.flush();        } catch (JRRuntimeException | JRException | IOException exception) {            LOGGER.error("Jasper Report Error", exception);            modelAndView = new ModelAndView("common/xls-down-result");            modelAndView.addObject("result", "error");            modelAndView.addObject("resultMessage", exception.getMessage());            return modelAndView;        } finally {            DataSourceUtils.releaseConnection(oConnection, dataSource);            if (oExporterOutput != null) {                oExporterOutput.close();            }            if (oOuputStream != null) {                oOuputStream.close();            }        }        return modelAndView;    }[/code]

Thank you!

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...