public PDFResponseModel generatePDF(String fileName, String template, String bucketName, Collection<?> items, Map<String, Object> parameters) throws ClassNotFoundException, JRException, IOException { JasperPrint jasperPrint; InputStream inputStream = null; JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(items); try { inputStream = storageUtil.getInputStream(bucketName, template); jasperPrint = JasperFillManager.fillReport(JasperCompileManager.compileReport( inputStream), parameters, beanColDataSource); byte[] pdfBytes = JasperExportManager.exportReportToPdf(jasperPrint); return new PDFResponseModel(fileName, pdfBytes); } catch (ClassNotFoundException | JRException | IOException e) { xLogger.severe("Failed to generate PDF for file name - ", fileName, e); throw e; } finally { if (inputStream != null) { inputStream.close(); } } }
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception { res.setContentType("text/xml"); res.setHeader("Content-Disposition", "inline; filename=\"file.jrpxml\""); JRXmlExporter exporter = new JRXmlExporter(DefaultJasperReportsContext.getInstance()); JasperPrint jasperPrint=this.getJasperPrint(req); exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); //exporter.setParameter(JRExporterParameter.START_PAGE_INDEX, Integer.valueOf(1)); 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(); } } }
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception { String fileName=this.getExportFileName(req); fileName+=".rtf"; res.setContentType("application/octet-stream"); res.setHeader("Connection", "close"); res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\""); JRRtfExporter exporter = new JRRtfExporter(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(); } } }
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception { res.setContentType("text/html;charset=UTF-8"); JRHtmlExporter exporter=new JRHtmlExporter(DefaultJasperReportsContext.getInstance()); JasperPrint jasperPrint=this.getJasperPrint(req); req.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); OutputStream ouputStream = res.getOutputStream(); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); String path=req.getContextPath(); if(path.endsWith("/")){ path+="dorado/bdf2/jasperreports/html.image"; }else{ path+="/dorado/bdf2/jasperreports/html.image"; } exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,path+"?image="); try { exporter.exportReport(); } catch (JRException e) { throw new ServletException(e); } finally { if (ouputStream != null) { ouputStream.flush(); ouputStream.close(); } } }
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception { String fileName=this.getExportFileName(req); fileName+=".pptx"; res.setContentType("application/octet-stream"); res.setHeader("Connection", "close"); res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\""); JRPptxExporter exporter = new JRPptxExporter(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(); } } }
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(); } } }
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception { String fileName=this.getExportFileName(req); fileName+=".csv"; res.setContentType("application/octet-stream"); res.setHeader("Connection", "close"); res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\""); JRCsvExporter exporter = new JRCsvExporter(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(); } } }
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception { String fileName=this.getExportFileName(req); fileName+=".docx"; res.setContentType("application/octet-stream"); res.setHeader("Connection", "close"); res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\""); JRDocxExporter exporter = new JRDocxExporter(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(); } } }
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception { String fileName=this.getExportFileName(req); fileName+=".xls"; res.setContentType("application/octet-stream"); res.setHeader("Connection", "close"); res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\""); JRXlsExporter exporter = new JRXlsExporter(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); } }
/** * Abre um relatório usando um datasource genérico. * * @param titulo Título usado na janela do relatório. * @param inputStream InputStream que contém o relatório. * @param parametros Parâmetros utilizados pelo relatório. * @param dataSource Datasource a ser utilizado pelo relatório. * @throws JRException Caso ocorra algum problema na execução do relatório */ public static void openReport( String titulo, InputStream inputStream, Map parametros, JRDataSource dataSource ) throws JRException { /* * Cria um JasperPrint, que é a versão preenchida do relatório, * usando um datasource genérico. */ JasperPrint print = JasperFillManager.fillReport( inputStream, parametros, dataSource ); // abre o JasperPrint em um JFrame viewReportFrame( titulo, print ); }
public void loadReport(String reportName, ReportObject reportObject) { logging = LoggingEngine.getInstance(); try { final InputStream inputStream = ShowReport.class .getResourceAsStream("/com/coder/hms/reportTemplates/" + reportName + ".jrxml"); JasperReport report = JasperCompileManager.compileReport(inputStream); HashMap<String, Object> parameters = new HashMap<String, Object>(); List<ReportObject> list = new ArrayList<ReportObject>(); list.add(reportObject); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(list); JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, beanColDataSource); final JRViewer viewer = new JRViewer(jasperPrint); setType(Type.POPUP); setResizable(false); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); this.setTitle("Reservation [Report]"); this.setExtendedState(Frame.MAXIMIZED_BOTH); this.setAlwaysOnTop(isAlwaysOnTopSupported()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new BorderLayout()); this.setIconImage(Toolkit.getDefaultToolkit(). getImage(LoginWindow.class.getResource(LOGOPATH))); this.setResizable(false); getContentPane().add(viewer, BorderLayout.CENTER); } catch (JRException e) { logging.setMessage("JRException report error!"); } }
@Test public void testInvoice(){ List<InvoiceItem> invoiceItems = new ArrayList<>(); int count = 1; for (IDemandItem demandItem : getDemandItems()) { InvoiceItem invoiceItem = new InvoiceItem(); invoiceItem.setItem(demandItem.getMaterialId().toString()); invoiceItem.setQuantity(demandItem.getQuantity().toString()); invoiceItem.setRecommended(demandItem.getRecommendedOrderQuantity().toString()); invoiceItem.setRemarks("Blah"); invoiceItem.setBatchId("AB/1234/56"+count); invoiceItem.setExpiry("11/03/2020"); invoiceItem.setManufacturer("Serum"); invoiceItem.setBatchQuantity(BigDecimal.TEN.toPlainString()); invoiceItem.setSno(String.valueOf(count++)); invoiceItems.add(invoiceItem); } JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(invoiceItems); try { Map<String, Object> hm = new HashMap<>(); JasperPrint jasperPrint = JasperFillManager.fillReport( JasperCompileManager .compileReport(Thread.currentThread().getContextClassLoader().getResourceAsStream( "test_logistimo_invoice.jrxml")), hm, beanColDataSource); JasperExportManager.exportReportToPdfFile(jasperPrint, "/tmp/logistimo_invoice.pdf"); } catch (Exception e) { e.printStackTrace(); } }
/** * @param jrxmlTemplate * @param jsonData * @param parameters * @param destFileName * @return */ public static String createReportFile(String jrxmlTemplate, String jsonData, Map<String, Object> parameters, String destFileName) { try { // fix json enter char jsonData = quoteHTML(jsonData); JasperReport reportTemplate = JRReportTemplate.getJasperReport(jrxmlTemplate); JRJSONDataSource dataSource = JRJSONDataSource.getInstance(jsonData); JasperPrint jasperPrint = getJasperPrint(reportTemplate, parameters, dataSource); return exportReport(jasperPrint, destFileName, DocType.PDF); } catch (Exception e) { _log.error(e); return StringPool.BLANK; } }
/** * @param jrxmlTemplate * @param jsonData * @param parameters * @param outputDestination * @param exportName * @return */ public static String createReportPDFFile(String jrxmlTemplate, String jsonData, Map<String, Object> parameters, String outputDestination, String exportName) { String sourceFileName = outputDestination + exportName; try { // fix json enter char jsonData = quoteHTML(jsonData); JasperReport reportTemplate = JRReportTemplate.getJasperReport(jrxmlTemplate); JRJSONDataSource dataSource = JRJSONDataSource.getInstance(jsonData); JasperPrint jasperPrint = getJasperPrint(reportTemplate, parameters, dataSource); return exportPdfFile(jasperPrint, sourceFileName); } catch (Exception e) { _log.error(e); return StringPool.BLANK; } }
private void krijoRaport(String pnt){ btnRaporti.setOnAction(e -> { Thread t = new Thread(new Runnable() { @Override public void run() { try { Connection conn = DriverManager.getConnection(CON_STR, "test", "test"); HashMap hm = new HashMap(); hm.put("Folderi", folderi); hm.put("punetori", pnt); JasperReport jreport = JasperCompileManager.compileReport(raportiPunetor); JasperPrint jprint = JasperFillManager.fillReport(jreport, hm, conn); JasperViewer.viewReport(jprint, false); conn.close(); }catch (Exception ex){ex.printStackTrace();} } }); t.start(); }); }
/** * */ public void xlsx() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/AllChartsReport.jrprint"); Map<String, String> dateFormats = new HashMap<String, String>(); dateFormats.put("EEE, MMM d, yyyy", "ddd, mmm d, yyyy"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xlsx"); JRXlsxExporter exporter = new JRXlsxExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); configuration.setOnePagePerSheet(true); configuration.setDetectCellType(true); configuration.setFormatPatternsMap(dateFormats); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("XLSX creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void xls() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/DataSourceReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); JRXlsExporter exporter = new JRXlsExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); configuration.setOnePagePerSheet(false); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void xlsx() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/HyperlinkReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xlsx"); JRXlsxExporter exporter = new JRXlsxExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); configuration.setOnePagePerSheet(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("XLSX creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void xlsx() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/JRMDbReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xlsx"); JRXlsxExporter exporter = new JRXlsxExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); configuration.setOnePagePerSheet(false); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("XLSX creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public static void viewReport( JasperReportsContext jasperReportsContext, JasperPrint jasperPrint, boolean isExitOnClose, Locale locale, ResourceBundle resBundle ) { JasperViewer jasperViewer = new JasperViewer( jasperReportsContext, jasperPrint, isExitOnClose, locale, resBundle ); jasperViewer.setVisible(true); }
/** * */ public void xlsx() throws JRException { File[] files = getFiles(new File("build/reports"), "jrprint"); for(int i = 0; i < files.length; i++) { long start = System.currentTimeMillis(); File sourceFile = files[i]; JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xlsx"); JRXlsxExporter exporter = new JRXlsxExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); configuration.setOnePagePerSheet(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("Report : " + sourceFile + ". XLSX creation time : " + (System.currentTimeMillis() - start)); } }
@Test public void parameterParsing() throws Exception { Map<String, String> params = new HashMap<String, String>(); params.put("net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI", "/foo/bar"); AbstractJasperReportsView view = new AbstractJasperReportsView() { @Override protected void renderReport(JasperPrint filledReport, Map<String, Object> model, HttpServletResponse response) throws Exception { assertEquals("Invalid number of exporter parameters", 1, getConvertedExporterParameters().size()); net.sf.jasperreports.engine.JRExporterParameter key = net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI; Object value = getConvertedExporterParameters().get(key); assertNotNull("Value not mapped to correct key", value); assertEquals("Incorrect value for parameter", "/foo/bar", value); } }; view.setExporterParameters(params); setViewProperties(view); view.render(getModel(), request, response); }
@Override public void pageUpdated(JasperPrint jasperPrint, int pageIndex) { if (log.isDebugEnabled()) { log.debug("page " + pageIndex + " updated"); } lock(); try { // update the timestamp if the page is tracked if (trackedPages.containsKey(pageIndex)) { long timestamp = System.currentTimeMillis(); trackedPages.put(pageIndex, timestamp); } } finally { unlock(); } }
/** * */ public void pptx() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/ScriptletReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".pptx"); JRPptxExporter exporter = new JRPptxExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimplePptxReportConfiguration configuration = new SimplePptxReportConfiguration(); configuration.setProgressMonitor(new SimpleExportProgressMonitor()); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("PPTX creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void docx() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/ScriptletReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".docx"); JRDocxExporter exporter = new JRDocxExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleDocxReportConfiguration configuration = new SimpleDocxReportConfiguration(); configuration.setProgressMonitor(new SimpleExportProgressMonitor()); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("DOCX creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void xls() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/XlsDataSourceReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); JRXlsExporter exporter = new JRXlsExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); configuration.setOnePagePerSheet(false); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void ods() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/XChartReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".ods"); JROdsExporter exporter = new JROdsExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleOdsReportConfiguration configuration = new SimpleOdsReportConfiguration(); configuration.setOnePagePerSheet(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("ODS creation time : " + (System.currentTimeMillis() - start)); }
@Override public void pageGenerated(JasperPrint jasperPrint, int pageIndex) { if (log.isDebugEnabled()) { log.debug("page " + pageIndex + " generated"); } lock(); try { if (this.jasperPrint == null) { this.jasperPrint = jasperPrint; } pageCount = pageIndex + 1; pageCondition.signalAll(); } finally { unlock(); } }
/** * */ public void ods() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/HyperlinkReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".ods"); JROdsExporter exporter = new JROdsExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleOdsReportConfiguration configuration = new SimpleOdsReportConfiguration(); configuration.setOnePagePerSheet(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("ODS creation time : " + (System.currentTimeMillis() - start)); }
/** * This static method calculates all the X cuts for a list of pages. * * @param jasperPrint * The JasperPrint document. * @param startPageIndex * The first page to consider. * @param endPageIndex * The last page to consider. * @param offsetX * horizontal element position offset */ public static CutsInfo calculateXCuts(ExporterNature nature, JasperPrint jasperPrint, int startPageIndex, int endPageIndex, int offsetX) { CutsInfo xCuts = new CutsInfo(); List<JRPrintPage> pages = jasperPrint.getPages(); for (int pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++) { JRPrintPage page = pages.get(pageIndex); addXCuts(nature, page.getElements(), offsetX, xCuts); } // add a cut at the page width if there are not parts and if no element goes beyond the page width if (!jasperPrint.hasParts()) { int width = jasperPrint.getPageWidth(); int lastCut = xCuts.getLastCutOffset(); if (lastCut < width) { xCuts.addCutOffset(width); } } return xCuts; }
/** * */ public void ods() throws JRException { File[] files = getFiles(new File("build/reports"), "jrprint"); for(int i = 0; i < files.length; i++) { long start = System.currentTimeMillis(); File sourceFile = files[i]; JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".ods"); JROdsExporter exporter = new JROdsExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleOdsReportConfiguration configuration = new SimpleOdsReportConfiguration(); configuration.setOnePagePerSheet(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("Report : " + sourceFile + ". ODS creation time : " + (System.currentTimeMillis() - start)); } }
/** * Saves a pre-compiled report into a file. * * @param jasperPrint * JasperPrint object which contains a compiled report. * @param expType * The desired output type of the report. * @param exportParameters * Export parameters than can be added to configure the resulting report. * @param target * The file used to return the report. * @throws JRException * In case there is any error saving the report an exception is thrown with the error * message. */ public static void saveReport(JasperPrint jasperPrint, ExportType expType, Map<Object, Object> exportParameters, File target) throws JRException { switch (expType) { case CSV: saveCsvReportToFile(jasperPrint, target); break; case HTML: if (log.isDebugEnabled()) log.debug("JR: Print HTML"); saveHTMLReportToFile(jasperPrint, exportParameters, target); break; case PDF: JasperExportManager.exportReportToPdfFile(jasperPrint, target.getAbsolutePath()); break; case TXT: saveTxtReportToFile(jasperPrint, target); break; case XLS: saveExcelReportToFile(jasperPrint, exportParameters, target); break; case XML: JasperExportManager.exportReportToXmlFile(jasperPrint, target.getAbsolutePath(), true); break; } }
/** * Returns a pre-compiled report into an Output Stream. * * @param jasperPrint * JasperPrint object which contains a compiled report. * @param expType * The desired output type of the 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 saveReport(JasperPrint jasperPrint, ExportType expType, Map<Object, Object> exportParameters, OutputStream outputStream) throws JRException { switch (expType) { case CSV: saveCsvReportToOutputStream(jasperPrint, outputStream); break; case HTML: if (log.isDebugEnabled()) log.debug("JR: Print HTML"); saveHTMLReportToOutputStream(jasperPrint, exportParameters, outputStream); break; case PDF: savePDFReportToOutputStream(jasperPrint, exportParameters, outputStream); break; case TXT: saveTxtReportToOutputStream(jasperPrint, outputStream); break; case XLS: saveExcelReportToOutputStream(jasperPrint, exportParameters, outputStream); break; case XML: JasperExportManager.exportReportToXmlStream(jasperPrint, outputStream); break; } }
/** * */ public void xls() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/XChartReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); JRXlsExporter exporter = new JRXlsExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); configuration.setOnePagePerSheet(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("XLS creation time : " + (System.currentTimeMillis() - start)); }
/** * Generates an XLS report from a pre-compiled report and returns it into a file. * * @param jasperPrint * JasperPrint object which contains a compiled report. * @param exportParameters * Export parameters than can be added to configure the resulting report. * @param file * The file used to return the report. * @throws JRException * In case there is any error generating the report an exception is thrown with the * error message. */ private static void saveExcelReportToFile(JasperPrint jasperPrint, Map<Object, Object> exportParameters, File file) throws JRException { final JRXlsExporter excelExporter = new JRXlsExporter(); SimpleExporterInput exporterInput = new SimpleExporterInput(jasperPrint); SimpleOutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(file); if (exportParameters != null && exportParameters.size() > 0) { SimpleXlsReportConfiguration exportConfiguration = getXlsConfigurationFromExportParameters(exportParameters); excelExporter.setConfiguration(exportConfiguration); } else { SimpleXlsReportConfiguration reportExportConfiguration = new SimpleXlsReportConfiguration(); reportExportConfiguration.setOnePagePerSheet(false); reportExportConfiguration.setRemoveEmptySpaceBetweenRows(true); excelExporter.setConfiguration(reportExportConfiguration); } excelExporter.setExporterInput(exporterInput); excelExporter.setExporterOutput(exporterOutput); excelExporter.exportReport(); }
/** * */ public void xlsx() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/StretchReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xlsx"); JRXlsxExporter exporter = new JRXlsxExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); configuration.setOnePagePerSheet(false); configuration.setFontSizeFixEnabled(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("XLSX creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void xls() throws JRException { File[] files = getFiles(new File("build/reports"), "jrprint"); for(int i = 0; i < files.length; i++) { long start = System.currentTimeMillis(); File sourceFile = files[i]; JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"); JRXlsExporter exporter = new JRXlsExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); configuration.setOnePagePerSheet(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("Report : " + sourceFile + ". XLS creation time : " + (System.currentTimeMillis() - start)); } }
private static void gerarDanfe(String url, List<String> emit, List<String> dest, List<String> nota, JRDataSource itens, String qrcode){ try { // Teste //String compilado = System.getProperty("user.dir") + "/danfe_nfce_80.jasper";; String output = "danfe.pdf"; map.put("emit", emit); map.put("dest", dest); map.put("nota", nota); map.put("qrcode", qrcode); // Relatório compilado JasperReport report = (JasperReport) JRLoader.loadObjectFromFile(url); //InputStream jasperStream = getClass().getResourceAsStream("/Foo.jasper"); //JasperReport report = (JasperReport) JRLoader.loadObject(jasperStream); // Relatório nao compilado //JasperReport report = JasperCompileManager.compileReport(jrxml); JasperPrint print = JasperFillManager.fillReport(report, map, itens); JasperExportManager.exportReportToPdfFile(print, output); } catch (JRException e) { System.out.println("erro: "+e.getMessage()); } }
/** * */ public void xlsx() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/HtmlComponentReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xlsx"); JRXlsxExporter exporter = new JRXlsxExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); configuration.setOnePagePerSheet(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("XLSX creation time : " + (System.currentTimeMillis() - start)); }