public void export(HttpServletRequest req, HttpServletResponse res) throws Exception { String fileName=this.getExportFileName(req); fileName+=".pdf"; res.setContentType("application/octet-stream"); res.setHeader("Connection", "close"); res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\""); JRPdfExporter exporter = new JRPdfExporter(DefaultJasperReportsContext.getInstance()); JasperPrint jasperPrint=this.getJasperPrint(req); exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); OutputStream ouputStream = res.getOutputStream(); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); try { exporter.exportReport(); } catch (JRException e) { throw new ServletException(e); } finally { if (ouputStream != null) { ouputStream.flush(); ouputStream.close(); } } }
/** * Generates a PDF report from a pre-compiled report and returns it into an output stream. * * @param jasperPrint * JasperPrint object which contains a compiled report. * @param exportParameters * Export parameters than can be added to configure the resulting report. * @param outputStream * The output stream used to return the report. * @throws JRException * In case there is any error generating the report an exception is thrown with the * error message. */ public static void savePDFReportToOutputStream(JasperPrint jasperPrint, Map<Object, Object> exportParameters, OutputStream outputStream) throws JRException { if (exportParameters != null && exportParameters.size() > 0) { final JRPdfExporter exporter = new JRPdfExporter(); SimpleExporterInput exporterInput = new SimpleExporterInput(jasperPrint); SimpleOutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput( outputStream); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); String jsContent = (String) exportParameters.get(PDF_JAVASCRIPT); if (jsContent != null) { configuration.setPdfJavaScript(jsContent); } exporter.setExporterInput(exporterInput); exporter.setExporterOutput(exporterOutput); exporter.setConfiguration(configuration); exporter.exportReport(); } else { JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream); } }
@Override public void execute(Connection connection) throws SQLException { InputStream relatorioStream = this.getClass().getResourceAsStream(this.caminhoRelatorio); try { JasperPrint print = JasperFillManager.fillReport(relatorioStream, this.parametros, connection); this.relatorioGerado = print.getPages().size() > 0; if (this.relatorioGerado) { JRExporter exportador = new JRPdfExporter(); exportador.setParameter(JRExporterParameter.OUTPUT_STREAM, this.response.getOutputStream()); exportador.setParameter(JRExporterParameter.JASPER_PRINT, print); this.response.setContentType("application/pdf"); this.response .setHeader("Content-Disposition", "attachment; filename=\"" + this.nomeArquivoSaida + "\""); exportador.exportReport(); } } catch (Exception e) { throw new SQLException("Erro ao executar relatorio " + this.caminhoRelatorio, e); } }
@Override public byte[] exportToPdf(final JasperPrint jasperPrint) { final JRPdfExporter exporter = new JRPdfExporter(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream); exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF8"); try { exporter.exportReport(); } catch (JRException e) { throw new AdempiereException("Cannot create PDF from " + jasperPrint, e); } return outputStream.toByteArray(); }
/** * Returns a PDF file into an output stream as result of the concatenation of the JasperPrint * objects list passed as parameter. * * @param jasperPrintList * A list of JasperPrint objects. * @param createBookmarks * A flag to indicate if the document should contain bookmarks, to mark the beginning of * each individual document that was part of the initial document list. * @param outputStream * The output stream used for returning the report. * @param reportConfiguration * An optional configuration for the report. * @throws JRException * In case there is any error compiling the report an exception is thrown with the error * message. */ public static void concatPDFReport(List<JasperPrint> jasperPrintList, boolean createBookmarks, OutputStream outputStream, SimplePdfExporterConfiguration reportConfiguration) throws JRException { JRPdfExporter exporter = new JRPdfExporter(); SimpleOutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput( outputStream); SimplePdfExporterConfiguration configuration = reportConfiguration != null ? reportConfiguration : new SimplePdfExporterConfiguration(); reportConfiguration.setCreatingBatchModeBookmarks(createBookmarks); exporter.setConfiguration(configuration); exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList)); exporter.setExporterOutput(exporterOutput); exporter.exportReport(); }
/** * Returns an encrypted PDF file into an output stream as result of the concatenation of the * JasperPrint objects list passed as parameter. * * @param jasperPrintList * A list of JasperPrint objects. * @param createBookmarks * A flag to indicate if the document should contain bookmarks, to mark the beginning of * each individual document that was part of the initial document list. * @param userPassword * A String that contains the user password of the resulting document. * @param ownerPassword * A String that contains the owner password of the resulting document. * @param outputStream * The output stream used for returning the report. * @throws JRException * In case there is any error compiling the report an exception is thrown with the error * message. */ public static void concatPDFReportEncrypted(List<JasperPrint> jasperPrintList, boolean createBookmarks, String userPassword, String ownerPassword, OutputStream outputStream) throws JRException { JRPdfExporter exporter = new JRPdfExporter(); SimpleOutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput( outputStream); SimplePdfExporterConfiguration reportConfiguration = new SimplePdfExporterConfiguration(); reportConfiguration.setEncrypted(true); reportConfiguration.set128BitKey(true); reportConfiguration.setUserPassword(userPassword); reportConfiguration.setOwnerPassword(ownerPassword); reportConfiguration.setCreatingBatchModeBookmarks(createBookmarks); exporter.setConfiguration(reportConfiguration); exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList)); exporter.setExporterOutput(exporterOutput); exporter.exportReport(); }
/** * */ public void pdf() throws JRException { long start = System.currentTimeMillis(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(new SimpleExporterInput("build/reports/BookReport.jrprint")); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("build/reports/BookReport.pdf")); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setCreatingBatchModeBookmarks(true); exporter.setConfiguration(configuration); exporter.exportReport(); //JasperExportManager.exportReportToPdfFile("build/reports/BookReport.jrprint"); System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void pdf() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/PdfEncryptReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".pdf"); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setEncrypted(true); configuration.set128BitKey(true); configuration.setUserPassword("jasper"); configuration.setOwnerPassword("reports"); configuration.setPermissions(PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void pdf() throws JRException { long start = System.currentTimeMillis(); List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>(); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report1.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report2.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report3.jrprint")); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("build/reports/BatchExportReport.pdf")); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setCreatingBatchModeBookmarks(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); }
@Override public void exportElement( JRPdfExporterContext exporterContext, JRGenericPrintElement element ) { try { JRPdfExporter exporter = (JRPdfExporter)exporterContext.getExporterRef(); exporter.exportImage(MapElementImageProvider.getImage(exporterContext.getJasperReportsContext(), element)); } catch (Exception e) { throw new RuntimeException(e); } }
/** * 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; }
private void exportPrintObject(ReporterConfig rc, final JasperPrint print, final ComponentExecutionApi reporter) { // build the export filename String filename = buildFilename(reporter, rc); // do each export option if (rc.isCsv()) { export(new JRCsvExporter(), print, filename, "csv", rc.isOpenExportFile()); } if (rc.isDocx()) { export(new JRDocxExporter(), print, filename, "docx", rc.isOpenExportFile()); } if (rc.isOdt()) { export(new JROdtExporter(), print, filename, "odt", rc.isOpenExportFile()); } if (rc.isHtml()) { export(new JRHtmlExporter(), print, filename, "html", rc.isOpenExportFile()); } if (rc.isPdf()) { export(new JRPdfExporter(), print, filename, "pdf", rc.isOpenExportFile()); } if (rc.isXls()) { export(new JRXlsExporter(), print, filename, "xls", rc.isOpenExportFile()); } // do show viewer at the end so it pops up after everything else if (rc.isShowViewer()) { reporter.submitControlLauncher(new ControlLauncherCallback() { @Override public void launchControls(ComponentControlLauncherApi launcherApi) { class DisposableViewer extends JRViewer implements Disposable { DisposableViewer(JasperPrint jrPrint) { super(jrPrint); } @Override public void dispose() { } } DisposableViewer viewer = new DisposableViewer(print); launcherApi.registerPanel("report", null, viewer, true); } }); } }
public static byte[] getPdf(JasperPrint jasperPrint) throws JRException { byte[] content = null; ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); content = getBytes(exporter, baos, jasperPrint); } finally { if (baos != null) { try { baos.flush(); baos.close(); } catch (Exception e) { e.printStackTrace(); } } } return content; }
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) { } }
/** * Метод генерации PDF-отчетов через файл. Вынесен в отдельный метод для синхронизации. * * @param jasperPrint этот готовый отчет и экспортим в PDF * @return возвращает готовый отчет в виде массива байт */ synchronized private static byte[] genPDF(JasperPrint jasperPrint) throws JRException, FileNotFoundException, IOException { // сгенерим отчет во временный файл JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, Uses.TEMP_FOLDER + File.separator + "temppdf.pdf"); exporter.exportReport(); // отправим данные из файла и удалим его final File pdf = new File(Uses.TEMP_FOLDER + File.separator + "temppdf.pdf"); final FileInputStream inStream = new FileInputStream(pdf); pdf.delete(); return Uses.readInputStream(inStream); }
@Override protected AbstractJasperReportsView getViewImplementation() { ConfigurableJasperReportsView view = new ConfigurableJasperReportsView(); view.setExporterClass(JRPdfExporter.class); view.setUseWriter(false); view.setContentType("text/html"); return view; }
@Test public void renderWithOutputStream() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); JasperPrint print = JasperFillManager.fillReport(getReport(), getParameters(), getDataSource()); JasperReportsUtils.render(new JRPdfExporter(), print, os); byte[] output = os.toByteArray(); assertPdfOutputCorrect(output); }
public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element) { JRPdfExporter exporter = (JRPdfExporter)exporterContext.getExporterRef(); JRPrintText text = getTextElementReplacement(exporterContext, element); try { exporter.exportText(text); } catch (Exception e) { throw new RuntimeException(e); } }
@Override 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(getJasperReportsContext()); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file)); exporter.exportReport(); } }
/** * 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 void exportToPdfFile( JasperPrint jasperPrint, String destFileName ) throws JRException { /* */ JRPdfExporter exporter = new JRPdfExporter(jasperReportsContext); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFileName)); exporter.exportReport(); }
/** * 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 void exportToPdfStream( JasperPrint jasperPrint, OutputStream outputStream ) throws JRException { JRPdfExporter exporter = new JRPdfExporter(jasperReportsContext); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(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 byte[] exportToPdf(JasperPrint jasperPrint) throws JRException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(jasperReportsContext); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos)); exporter.exportReport(); return baos.toByteArray(); }
private static void exportPDF(JasperPrint jasperPrint) throws Exception { File file = new File("D:/test.pdf"); System.out.println("Exporting PDF to " + file); { JRPdfExporter exporter = new JRPdfExporter(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream); exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF8"); // JRProperties.setProperty(JRFont.DEFAULT_PDF_FONT_NAME, "arial.ttf"); exporter.exportReport(); writeBytes(file, outputStream.toByteArray()); } }
/** * @param pdfBytes * @param xmlBytes * @param pdfName * @param xmlName * @throws JazzOMRException * @throws FileNotFoundException * @throws IOException */ protected void logExportedFiles(byte[] pdfBytes, byte[] xmlBytes, String pdfName, String xmlName) { if(!log.isDebugEnabled()) return; byte[] pdfFromXML; try { ByteArrayInputStream bais = new ByteArrayInputStream(xmlBytes); JasperPrint jasperPrint = JRPrintXmlLoader.load(bais); JRPdfExporter pdfExporter = new JRPdfExporter(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baosPDF); pdfExporter.exportReport(); pdfFromXML = baosPDF.toByteArray(); } catch (JRException e) { throw new JazzRuntimeException("erro ao tentar montar relatorio resultado do XML!", e); } writeToFile(pdfFromXML, "fromXML_"+pdfName); writeToFile(pdfBytes, pdfName); writeToFile(xmlBytes, xmlName); }
/** * * @param jp * @return */ private DataHandler exportToDataHandlerPDF(JasperPrint jp) { ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baosPDF); try { exporter.exportReport(); } catch (JRException e1) { throw new JazzOMRRuntimeException("Erro ao tentar exportar relatorio", e1); } byte[] xmlBytes = null; try { baosPDF.flush(); xmlBytes = baosPDF.toByteArray(); baosPDF.close(); } catch (IOException e) { throw new JazzOMRRuntimeException("Erro ao tentar exportar relatorio", e); } DataSource source = new ByteArrayDataSource(xmlBytes, "application/pdf"); DataHandler dataHandler = new DataHandler(source); return dataHandler; }
/** * * @param jp * @return */ private DataHandler exportToDataHandlerPDF(JasperPrint jp) { ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baosPDF); try { exporter.exportReport(); } catch (JRException e1) { throw new JazzRuntimeException("Erro ao tentar exportar relatorio", e1); } byte[] xmlBytes = null; try { baosPDF.flush(); xmlBytes = baosPDF.toByteArray(); baosPDF.close(); } catch (IOException e) { throw new JazzRuntimeException("Erro ao tentar exportar relatorio", e); } DataSource source = new ByteArrayDataSource(xmlBytes, "application/pdf"); DataHandler dataHandler = new DataHandler(source); return dataHandler; }
private static JRExporter getJREXporter(final String extension) { if ("pdf".equalsIgnoreCase(extension)) { JRPdfExporter exporter = new JRPdfExporter(); // exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print();"); return exporter; } else if ("html".equalsIgnoreCase(extension)) { return new JRHtmlExporter(); } else if ("xls".equalsIgnoreCase(extension)) { JRXlsExporter exporterXLS = new JRXlsExporter(); exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); return exporterXLS; } else if ("txt".equalsIgnoreCase(extension)) { return new JRTextExporter(); } else if ("csv".equalsIgnoreCase(extension)) { return new JRCsvExporter(); } else if ("docx".equalsIgnoreCase(extension)) { return new JRDocxExporter(); } return null; }
@Override protected JRPdfExporter getExporter(JasperReportsConfiguration jContext, JRExportProgressMonitor monitor, File file) { JRPdfExporter exp = new JRPdfExporter(jContext); exp.setExporterOutput(new SimpleOutputStreamExporterOutput(file)); SimplePdfExporterConfiguration conf = new SimplePdfExporterConfiguration(); exp.setConfiguration(conf); SimplePdfReportConfiguration rconf = new SimplePdfReportConfiguration(); setupReportConfiguration(rconf, monitor); exp.setConfiguration(rconf); return exp; }
public void testRenderWithOutputStream() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); JasperPrint print = JasperFillManager.fillReport(getReport(), getParameters(), getDataSource()); JasperReportsUtils.render(new JRPdfExporter(), print, os); byte[] output = os.toByteArray(); assertPdfOutputCorrect(output); }
/** * Exports by MIME type. * * @param mimeType MIME type * @param jp Jasper print * @param os outputstream * @throws JRException */ protected void export(String mimeType, JasperPrint jp, OutputStream os) throws JRException { if ("application/pdf".equalsIgnoreCase(mimeType)) { exportReport(new JRPdfExporter(), jp, os); } else if ("text/xml".equalsIgnoreCase(mimeType)) { exportReport(new HtmlExporter(), jp, os); } else if ("application/rtf".equalsIgnoreCase(mimeType)) { exportReport(new JRRtfExporter(), jp, os); } else if ("application/xls".equalsIgnoreCase(mimeType)) { exportReport(new JRXlsExporter(), jp, os); } else if ("application/odt".equalsIgnoreCase(mimeType)) { exportReport(new JROdtExporter(), jp, os); } else if ("application/ods".equalsIgnoreCase(mimeType)) { exportReport(new JROdsExporter(), jp, os); } else if ("application/docx".equalsIgnoreCase(mimeType)) { exportReport(new JRDocxExporter(), jp, os); } else if ("application/xlsx".equalsIgnoreCase(mimeType)) { exportReport(new JRXlsxExporter(), jp, os); } else if ("application/pptx".equalsIgnoreCase(mimeType)) { exportReport(new JRPptxExporter(), jp, os); } else if ("text/xhmtl".equalsIgnoreCase(mimeType)) { exportReport(new JRXhtmlExporter(), jp, os); } else { throw new IllegalArgumentException("JasperRenderer does not support " + mimeType + " MIME type."); } }
private void exportToPDF() { log.debug("exporting to PDF"); pdfExporter = new JRPdfExporter(); pdfExporter.setParameters(getExportParameters()); try { start = System.currentTimeMillis(); pdfExporter.exportReport(); log.info("export running time (msec): " + (System.currentTimeMillis() - start)); } catch (JRException jre) { jre.printStackTrace(); log.error(jre.getCause()); } }
@Override public void export(JasperPrint jasper_print, OutputStream stream, SimpleReportExportConfiguration config, Map<String, byte[]> images) throws JRException { JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(new SimpleExporterInput(jasper_print)); exporter.setConfiguration((PdfReportConfiguration) config); SimpleOutputStreamExporterOutput output = new SimpleOutputStreamExporterOutput(stream); exporter.setExporterOutput(output); exporter.exportReport(); }
@SuppressWarnings("deprecation") private static byte[] getBytes(JRAbstractExporter exporter, ByteArrayOutputStream baos, JasperPrint jasperPrint) throws JRException { printNextReportsParameters(); // for csv delimiter //exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, ";"); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); if (exporter instanceof JRPdfExporter) { exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, encoding); // create embedded pdf font (like in nextreports) if (embeddedFont != null) { HashMap<FontKey, PdfFont> fontMap = new HashMap<FontKey, PdfFont>(); FontKey key = new FontKey("Arial", false, false); PdfFont font = new PdfFont(embeddedFont, BaseFont.IDENTITY_H, true); fontMap.put(key, font); exporter.setParameter(JRPdfExporterParameter.FONT_MAP, fontMap); } } else { exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); } exporter.exportReport(); return baos.toByteArray(); }
@Override public void exportElement(JRPdfExporterContext exporterContext, JRGenericPrintElement element) { try { JRPdfExporter exporter = (JRPdfExporter) exporterContext.getExporter(); JRPrintImage image = WmsMapElementImageProvider.getImage( exporterContext.getJasperReportsContext(), element); exporter.exportImage(image); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Exports the report to a file in PDF format. * * @param filename file path of the exported report * @throws JRException if an error during exporting occurs */ public void exportFile(String filename) throws JRException { JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, filledReportPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, filename); exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); exporter.exportReport(); }
/** * Writes the report into the OutputStream in PDF format. * * @param filename filename of the exported report * @param out the output stream to print the report to * @throws JRException if an error during exporting occurs */ public void exportStream(String filename, OutputStream out) throws JRException { JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, filledReportPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, filename); exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out); exporter.exportReport(); }