JRExporter exporter = null; exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream); exporter.exportReport();
JRExporter exporter = new JRExporter(); ByteArrayOutputStream os=new ByteArrayOutputStream(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os); exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BACKGROUND, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "inline;filename=" + "one.xls"); response.getOutputStream().write(os.toByteArray());
protected ReportWriter(final JasperPrint _jasperPrint, final JRExporter _exporter) { jasperPrint = _jasperPrint; exporter = _exporter; exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); }
exporter.setParameters(exportPara); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, arrayOutputStream); exporter.exportReport(); _imageMap = (Map)exporter.getParameter(JRHtmlExporterParameter.IMAGES_MAP); return _media = new AMedia("report.pdf", "pdf", "application/pdf", arrayOutputStream.toByteArray()); exporter.setParameters(exportPara); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, arrayOutputStream); exporter.exportReport(); _imageMap = (Map)exporter.getParameter(JRHtmlExporterParameter.IMAGES_MAP); return _media = new AMedia("report.xml", "xml", "text/xml", arrayOutputStream.toByteArray()); exporter.setParameters(exportPara); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, arrayOutputStream); exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, new HashMap()); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, IMAGE_DIR); exporter.exportReport(); _imageMap = (Map)exporter.getParameter(JRHtmlExporterParameter.IMAGES_MAP); return _media = new AMedia("report.html", "html", "text/html", arrayOutputStream.toByteArray());
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); request.getSession().setAttribute("net.sf.jasperreports.j2ee.jasper_print", jasperPrint); } else if (format.equals(FORMAT_XLS)) { if (exportParams != null) { LOG.debug("Found export parameters; adding to exporter parameters..."); exporter.getParameters().putAll(exportParams);
public static InputStream exportToHtml(HttpServletRequest request, String imageServletUrl, JasperPrint jasperPrint, Map<JRExporterParameter,Object> exporterParams) throws JRException, IOException { if (exporterParams == null) exporterParams = new HashMap<JRExporterParameter,Object>(); exporterParams.put(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl); final ReportWriter reportWriter = ReportWriterFactory.build(pageTreshold.get()).getReportWriter(jasperPrint, DJConstants.FORMAT_HTML, exporterParams); Map imagesMap = new HashMap(); JRExporter exporter = reportWriter.getExporter(); exporter.setParameters(exporterParams); setupParameters(request, imageServletUrl, jasperPrint, imagesMap, exporter); //write generated HTML to the http-response (the one you got from the helper) return reportWriter.write(); }
//... import javax.print.attribute.standard.Destination; //... JRExporter exporter = new JRPrintServiceExporter(); //--- Set print properties PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(MediaSizeName.ISO_A4); //---------------------------------------------------- printRequestAttributeSet.add(new Destination(new java.net.URI("file:d:/output/report.ps"))); //---------------------------------------------------- PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet(); printServiceAttributeSet.add(new PrinterName("Xerox DocuPrint 100 EPS PS3", null)); //--- Set print parameters exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE); //--- Print the document try{ exporter.exportReport(); } catch(JRException e){ e.printStackTrace(); }
/** * We need to write text to the response Writer. * @param exporter the JasperReports exporter to use * @param populatedReport the populated <code>JasperPrint</code> to render * @param response the HTTP response the report should be rendered to * @throws Exception if rendering failed */ protected void renderReportUsingWriter( JRExporter exporter, JasperPrint populatedReport, HttpServletResponse response) throws Exception { // Copy the encoding configured for the report into the response. String contentType = getContentType(); String encoding = (String) exporter.getParameter(JRExporterParameter.CHARACTER_ENCODING); if (encoding != null) { // Only apply encoding if content type is specified but does not contain charset clause already. if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) { contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding; } } response.setContentType(contentType); // Render report into HttpServletResponse's Writer. JasperReportsUtils.render(exporter, populatedReport, response.getWriter()); }
protected ReportWriter(final JasperPrint _jasperPrint, final JRExporter _exporter) { jasperPrint = _jasperPrint; exporter = _exporter; exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); }
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); request.getSession().setAttribute("net.sf.jasperreports.j2ee.jasper_print", jasperPrint); } else if (format.equals(FORMAT_XLS)) { if (exportParams != null) { LOG.debug("Found export parameters; adding to exporter parameters..."); exporter.getParameters().putAll(exportParams);
public static InputStream exportToHtml(HttpServletRequest request, String imageServletUrl, JasperPrint jasperPrint, Map<JRExporterParameter,Object> exporterParams) throws JRException, IOException { if (exporterParams == null) exporterParams = new HashMap<JRExporterParameter,Object>(); exporterParams.put(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl); final ReportWriter reportWriter = ReportWriterFactory.build(pageTreshold.get()).getReportWriter(jasperPrint, DJConstants.FORMAT_HTML, exporterParams); Map imagesMap = new HashMap(); JRExporter exporter = reportWriter.getExporter(); exporter.setParameters(exporterParams); setupParameters(request, imageServletUrl, jasperPrint, imagesMap, exporter); //write generated HTML to the http-response (the one you got from the helper) return reportWriter.write(); }
/** * We need to write text to the response Writer. * @param exporter the JasperReports exporter to use * @param populatedReport the populated {@code JasperPrint} to render * @param response the HTTP response the report should be rendered to * @throws Exception if rendering failed */ protected void renderReportUsingWriter(net.sf.jasperreports.engine.JRExporter exporter, JasperPrint populatedReport, HttpServletResponse response) throws Exception { // Copy the encoding configured for the report into the response. String contentType = getContentType(); String encoding = (String) exporter.getParameter(net.sf.jasperreports.engine.JRExporterParameter.CHARACTER_ENCODING); if (encoding != null) { // Only apply encoding if content type is specified but does not contain charset clause already. if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) { contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding; } } response.setContentType(contentType); // Render report into HttpServletResponse's Writer. JasperReportsUtils.render(exporter, populatedReport, response.getWriter()); }
List jpList = new ArrayList(); jpList.add(JRLoader.loadObjectFromFile("build/reports/Report1.jrprint")); ... JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jpList); exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, stream); exporter.exportReport();
private static void setupParameters(HttpServletRequest request, String imageServletUrl, JasperPrint jasperPrint, Map imagesMap, JRExporter exporter) { exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + "/" + imageServletUrl + "?image="); // Needed to support chart images: exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); HttpSession session = request.getSession(); session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); session.setAttribute("net.sf.jasperreports.j2ee.jasper_print", jasperPrint); }
public static void exportToHtml(HttpServletRequest request, HttpServletResponse response, String imageServletUrl, JasperPrint jasperPrint, Map<JRExporterParameter,Object> exporterParams) throws JRException, IOException { if (exporterParams == null) exporterParams = new HashMap<JRExporterParameter,Object> (); exporterParams.put(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl); final ReportWriter reportWriter = ReportWriterFactory.build(pageTreshold.get()).getReportWriter(jasperPrint, DJConstants.FORMAT_HTML, exporterParams); Map imagesMap = new HashMap(); JRExporter exporter = reportWriter.getExporter(); exporter.setParameters(exporterParams); setupParameters(request, imageServletUrl, jasperPrint, imagesMap, exporter); //write generated HTML to the http-response (the one you got from the helper) reportWriter.writeTo(response); }
/** * Render the supplied <code>JasperPrint</code> instance using the * supplied <code>JRAbstractExporter</code> instance and write the results * to the supplied <code>OutputStream</code>. * <p>Make sure that the <code>JRAbstractExporter</code> implementation you * supply is capable of writing to a <code>OutputStream</code>. * @param exporter the <code>JRAbstractExporter</code> to use to render the report * @param print the <code>JasperPrint</code> instance to render * @param outputStream the <code>OutputStream</code> to write the result to * @throws JRException if rendering failed */ public static void render(JRExporter exporter, JasperPrint print, OutputStream outputStream) throws JRException { exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream); exporter.exportReport(); }
private static void setupParameters(HttpServletRequest request, String imageServletUrl, JasperPrint jasperPrint, Map imagesMap, JRExporter exporter) { exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + "/" + imageServletUrl + "?image="); // Needed to support chart images: exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); HttpSession session = request.getSession(); session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); session.setAttribute("net.sf.jasperreports.j2ee.jasper_print", jasperPrint); }
public static void exportToHtml(HttpServletRequest request, HttpServletResponse response, String imageServletUrl, JasperPrint jasperPrint, Map<JRExporterParameter,Object> exporterParams) throws JRException, IOException { if (exporterParams == null) exporterParams = new HashMap<JRExporterParameter,Object> (); exporterParams.put(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl); final ReportWriter reportWriter = ReportWriterFactory.build(pageTreshold.get()).getReportWriter(jasperPrint, DJConstants.FORMAT_HTML, exporterParams); Map imagesMap = new HashMap(); JRExporter exporter = reportWriter.getExporter(); exporter.setParameters(exporterParams); setupParameters(request, imageServletUrl, jasperPrint, imagesMap, exporter); //write generated HTML to the http-response (the one you got from the helper) reportWriter.writeTo(response); }
/** * Render the supplied <code>JasperPrint</code> instance using the * supplied <code>JRAbstractExporter</code> instance and write the results * to the supplied <code>Writer</code>. * <p>Make sure that the <code>JRAbstractExporter</code> implementation * you supply is capable of writing to a <code>Writer</code>. * @param exporter the <code>JRAbstractExporter</code> to use to render the report * @param print the <code>JasperPrint</code> instance to render * @param writer the <code>Writer</code> to write the result to * @throws JRException if rendering failed */ public static void render(JRExporter exporter, JasperPrint print, Writer writer) throws JRException { exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, writer); exporter.exportReport(); }
public JRExporter getExporter(final String _format) { checkFormat(_format); final JRExporter exporter = FORMAT_INFO.get(_format).getExporterInstance(); //FIXME migrate to Exporter exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); return exporter; }