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) { } }
/** * Exports the generated report object received as first parameter into PDF format and * writes the results to the output stream specified by the second parameter. * * @param jasperPrint report object to export * @param outputStream output stream to write the resulting PDF content to * @see net.sf.jasperreports.engine.export.JRPdfExporter */ public static void exportReportToPdfStream( JasperPrint jasperPrint, OutputStream outputStream ) throws JRException { JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream); exporter.exportReport(); }
/** * Exports the generated report object received as parameter into PDF format and * returns the binary content as a byte array. * * @param jasperPrint report object to export * @return byte array representing the resulting PDF content * @see net.sf.jasperreports.engine.export.JRPdfExporter */ public static byte[] exportReportToPdf(JasperPrint jasperPrint) throws JRException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); exporter.exportReport(); return baos.toByteArray(); }
/** * Exports the generated report file specified by the first parameter into PDF format, * the result being placed in the second file parameter. * * @param jasperPrint report object to export * @param destFileName file name to place the PDF content into * @see net.sf.jasperreports.engine.export.JRPdfExporter */ public static void exportReportToPdfFile( JasperPrint jasperPrint, String destFileName ) throws JRException { /* */ JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileName); exporter.exportReport(); }
/** * */ public void save(JasperPrint jasperPrint, File file) throws JRException { if (!file.getName().toLowerCase().endsWith(EXTENSION_PDF)) { file = new File(file.getAbsolutePath() + EXTENSION_PDF); } if ( !file.exists() || JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog( null, MessageFormat.format( getBundleString("file.exists"), new Object[]{file.getName()} ), getBundleString("save"), JOptionPane.OK_CANCEL_OPTION ) ) { JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE, file); exporter.exportReport(); } }
/** * 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; }
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fbos); exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fbos); exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);