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

rldndvv

Members
  • Posts

    1
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Everything posted by rldndvv

  1. 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!
×
×
  • Create New...