Java Code Examples for net.sf.jasperreports.engine.export.JRPdfExporter#setParameter()
The following examples show how to use
net.sf.jasperreports.engine.export.JRPdfExporter#setParameter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfReport.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * generate a ByteArrayOutputStream from given JasperPrint object for the PDF report * * @param jasperPrint transform to pdf report * @return reporting ByteArrayOutputStream * @throws ReportingException when the JasperPrint null * @throws JRException * @throws IOException */ public ByteArrayOutputStream generatePdfReport(JasperPrint jasperPrint) throws JRException, ReportingException { ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream(); if (jasperPrint == null) { throw new ReportingException("jasperPrint null, can't convert to PDF report"); } try { JRPdfExporter jrPdfExporter = new JRPdfExporter(); jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, pdfOutputStream); jrPdfExporter.exportReport(); } catch (JRException e) { throw new JRException("Error occurred exporting PDF report ", e); } return pdfOutputStream; }
Example 2
Source File: GeneratePDFReport.java From elasticsearch-report-engine with GNU General Public License v3.0 | 5 votes |
private void exportPdf(JasperPrint jp, ByteArrayOutputStream baos, Map params) { // Create a JRPdfExporter instance JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); try { exporter.exportReport(); } catch (JRException e) { } }
Example 3
Source File: JasperReportsPdfExporter.java From tutorials with MIT License | 5 votes |
/** * Generates a ByteArrayOutputStream from the provided JasperReport using * the {@link JRPdfExporter}. After that, the generated bytes array is * written in the {@link HttpServletResponse} * * @param jp * The generated JasperReport. * @param fileName * The fileName of the exported JasperReport * @param response * The HttpServletResponse where generated report has been * written * @throws JRException * during JasperReport export. * @throws IOException * when writes the ByteArrayOutputStream into the * HttpServletResponse */ @Override public void export(JasperPrint jp, String fileName, HttpServletResponse response) throws JRException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Create a JRPdfExporter instance JRPdfExporter exporter = new JRPdfExporter(); // Here we assign the parameters jp and baos to the exporter exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); // Retrieve the exported report in PDF format exporter.exportReport(); // Specifies the response header response.setHeader("Content-Disposition", "inline; filename=" + fileName); // Make sure to set the correct content type // Each format has its own content type response.setContentType("application/pdf"); response.setContentLength(baos.size()); // Retrieve the output stream ServletOutputStream outputStream = response.getOutputStream(); // Write to the output stream baos.writeTo(outputStream); // Flush the stream outputStream.flush(); }