import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.util.JRLoader; public class QuickCompile { public static void main(String[] args) { try { String template = "..."; String compiled = "..."; JasperCompileManager.compileReportToFile(template, compiled); // Just as a test... JasperReport jr = (JasperReport) JRLoader.loadObjectFromFile(compiled); } catch (JRException exp) { exp.printStackTrace(); } } }
private void btnExportActionPerformed(java.awt.event.ActionEvent evt) { try { JasperPrint printer = JasperFillManager.fillReport(getClass().getResourceAsStream("reportRecharge.jasper"), params, new JREmptyDataSource()); JasperViewer jv = new JasperViewer(printer,false); jv.setVisible(true); } catch (JRException ex) { ex.printStackTrace(); } }
Iterator iter = template.iterator(); while (iter.hasNext();) { String fileName = (String) iter.next(); try { String file = JasperFillManager.fillReportToFile(basePath + templatesFolder +fileName, parameters, new JRBeanArrayDataSource(reportableObj)); printList.add(JRLoader.loadObject(file)); } catch (JRException e1) { e1.printStackTrace(); } }
public class JasperReportsIntro { public static void main(String[] args) { JasperReport jasperReport; JasperPrint jasperPrint; try { jasperReport = JasperCompileManager.compileReport("reports/jasperreports_demo.jrxml"); jasperPrint = JasperFillManager.fillReport( jasperReport, new HashMap(), new JREmptyDataSource()); JasperExportManager.exportReportToPdfFile( jasperPrint, "reports/simple_report.pdf"); } catch (JRException e) { e.printStackTrace(); } } }
JasperReport jasperReport = null; String reportName = "MySubreport.jrxml"; //load the the subreport jrxml from the classpath InputStream ins = this.getClass().getClassLoader().getResourceAsStream(reportName); JasperDesign design = JRXmlLoader.load(ins); try { jasperReport = JasperCompileManager.compileReport(design); } catch (JRException e) { e.printStackTrace(); } //pass the jasperReport object as a parameter to the report Map<String, Object> reportParams = new HashMap<String, Object>(); reportParams.put("SUB_JASPER", jasperReport); //finally pass the parameter map to the report.
ClassLoader classloader = Thread.currentThread().getContextClassLoader(); InputStream projectInputStream = classloader.getResourceAsStream("jasper/xyLineChart.jasper"); Map<String, Object> parameters = new HashMap<String, Object>(); for(int i = 0 ; i< coordinatesList.size() ; i++){ coordiantesListBean = new JRBeanCollectionDataSource(coordinatesList.get(i)); parameters.put("XYChartDataSource", coordiantesListBean); } try { JasperPrint jasperPrint = JasperFillManager.fillReport(projectInputStream, parameters, new JREmptyDataSource()); JasperExportManager.exportReportToPdfFile(jasperPrint,FILE_LOCATION); } catch (JRException e) { e.printStackTrace(); }
public void generateReport(ActionEvent actionEvent) throws FileNotFoundException { JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(PopulateBean.createBeanCollection()); Map parameters = new HashMap(); try { InputStream is = new FileInputStream(new File("Source path to template.jrxml")); OutputStream os=new FileOutputStream(new File("Resulting report.pdf")); JasperDesign jasperDesign = JRXmlLoader.load(is); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds); JasperExportManager.exportReportToPdfStream(jasperPrint, os); } catch (JRException e) { e.printStackTrace(); }
JasperReport jasperReport = null; JasperReport subReport = null; String reportPath = "/reports/invoice/invoice_master.jasper"; String subReportPath = "/reports/invoice/invoice_sub_report.jasper"; try { //load the the reports jasperReport = (JasperReport)JRLoader.loadObject(getClass().getResource(reportPath)); subReport = (JasperReport)JRLoader.loadObject(getClass().getResource(subReportPath)); //pass the subReport object as a parameter to the jasperReport Map<String, Object> reportParams = new HashMap<String, Object>(); params.put("SUB_JASPER", subReport); //finally pass the parameter map to the report. JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connectionOrOtherDataSource); //... do something with jasperPrint } catch (JRException e) { e.printStackTrace(); }
public JasperPrint run() { JasperPrint jasperPrint = null; try { jasperPrint = (JasperPrint)JRLoader.loadObject(url); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jasperPrint; } }
public static void main(String[] args) { if (args.length < 1) { System.out.println("Please supply the name of the report(s) source to compile."); System.exit(-1); } try { for (int i = 0; i < args.length; i++) { System.out.println("JasperReports Compiling: " + args[i]); JasperCompileManager.compileReportToFile(args[i]); } } catch (JRException e) { e.printStackTrace(); System.exit(-1); } System.exit(0); } }
private void exportToExcel(HttpServletResponse resp, JasperPrint jasperPrint) throws IOException { String reportfilename = tagreport("file") + "repor.xls"; JExcelApiExporter exporterXLS = new JExcelApiExporter(); exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT,jasperPrint); 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); exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, resp.getOutputStream()); resp.setHeader("Content-Disposition", "inline;filename="+ reportfilename); resp.setContentType("application/vnd.ms-excel"); try { exporterXLS.exportReport(); } catch (JRException e) { e.printStackTrace(); } }
public static void main(String[] args) { if (args.length < 1) { System.out.println("Please supply the name of the report(s) source to compile."); System.exit(-1); } try { for (int i = 0; i < args.length; i++) { System.out.println("JasperReports Compiling: " + args[i]); JasperCompileManager.compileReportToFile(args[i]); } } catch (JRException e) { e.printStackTrace(); System.exit(-1); } System.exit(0); } }
if (reportType.equals("excel")) { try { ServletOutputStream servletOutputStream = resp .getOutputStream(); JasperReport jasperReport = JasperCompileManager .compileReport(path + "Template/" + template); JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(list)); JRXlsxExporter exporter = new JRXlsxExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); ByteArrayOutputStream os = new ByteArrayOutputStream(); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os); exporter.exportReport(); resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); resp.setHeader("Content-Disposition", "attachment;filename="+ title + ".xlsx"); resp.getOutputStream().write(os.toByteArray()); resp.flushBuffer(); } catch (JRException e) { e.printStackTrace(); } } else {
public static void main(String[] args) { String sourceFileName = "C://tools/jasperreports-5.0.1/test/jasper_report_template.jasper"; DataBeanList DataBeanList = new DataBeanList(); ArrayList<DataBean> dataList = DataBeanList.getDataBeanList(); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataList); Map parameters = new HashMap(); /** * Passing ReportTitle and Author as parameters */ parameters.put("ReportTitle", "List of Contacts"); parameters.put("Author", "Prepared By Manisha"); try { JasperFillManager.fillReportToFile( sourceFileName, parameters, beanColDataSource); } catch (JRException e) { e.printStackTrace(); } }
public class ReportGenarator { public static String OUT_PUT = "your_output_file_path/myreport.docx"; public static String REPORT = "your_report_path/myreport.jrxml"; public void genarateReport(String reportPath, Map<String, Object> map, Connection con) { try { JasperReport jr = JasperCompileManager.compileReport( ClassLoader.getSystemResourceAsStream(reportPath)); JasperPrint jp = JasperFillManager.fillReport(jr, map, con); JRDocxExporter export = new JRDocxExporter(); export.setExporterInput(new SimpleExporterInput(jp)); export.setExporterOutput(new SimpleOutputStreamExporterOutput(new File(OUT_PUT))); SimpleDocxReportConfiguration config = new SimpleDocxReportConfiguration(); export.setConfiguration(config); export.exportReport(); } catch (JRException ex) { ex.printStackTrace(); } } }
/** * The main method. * * @param args the arguments */ public static void main(String[] args) { if (args.length > 1 && new File(args[0]).exists()) { System.setProperty("opennms.home", args[0]); } initializeSingleInstanceDatabase(); BeanUtils.getBeanFactory("jasperReportContext"); // To trigger Spring Initialization File reportsDirectory = new File(ConfigFileConstants.getFilePathString(), "report-templates"); System.out.printf("Analyzing jasper reports located at %s\n", reportsDirectory); for (File report : FileUtils.listFiles(reportsDirectory, new String[] { "jrxml" }, true)) { System.out.printf("Compiling report template %s\n", report.getAbsolutePath()); try { JasperCompileManager.compileReportToFile(report.getAbsolutePath()); } catch (JRException e) { System.err.println("Error: cannot compile report because: " + e.getMessage()); e.printStackTrace(); } } }
/** * The main method. * * @param args the arguments */ public static void main(String[] args) { if (args.length > 1 && new File(args[0]).exists()) { System.setProperty("opennms.home", args[0]); } initializeSingleInstanceDatabase(); BeanUtils.getBeanFactory("jasperReportContext"); // To trigger Spring Initialization File reportsDirectory = new File(ConfigFileConstants.getFilePathString(), "report-templates"); System.out.printf("Analyzing jasper reports located at %s\n", reportsDirectory); for (File report : FileUtils.listFiles(reportsDirectory, new String[] { "jrxml" }, true)) { System.out.printf("Compiling report template %s\n", report.getAbsolutePath()); try { JasperCompileManager.compileReportToFile(report.getAbsolutePath()); } catch (JRException e) { System.err.println("Error: cannot compile report because: " + e.getMessage()); e.printStackTrace(); } } }
public void doReport(final DynamicReport _report, final Collection _data, String name) { try { final JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(_report, new ClassicLayoutManager(), _data); // JasperViewer.viewReport(jasperPrint); ReportExporter.exportReport(jasperPrint, System.getProperty("user.dir")+ "/target/ReflectiveReportTest "+ name + ".pdf"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (JRException e) { e.printStackTrace(); } }
//... 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(); }
@Override public void fillManage(JRDataSource datasrc, final String anneeSelected, final String quaSig, final String nomSig, final String libEtab, final String fileName, final FacesContext facesContext, final Boolean sessionUnique) { final String sourceFileName = getPathJasperTemplate() + "report3.jasper"; final Map<String, Object> parameters = new HashMap<String, Object>() {{ put("annee", anneeSelected); put("etablissement", libEtab); put("qualite", quaSig); put("signataire", nomSig); put("sessionUnique", sessionUnique); }}; try { final JasperPrint jp = JasperFillManager.fillReport(sourceFileName, parameters, datasrc); if (jp != null) { byte[] contentPdf = JasperExportManager.exportReportToPdf(jp); setDownLoadAndSend(contentPdf, facesContext,"application/pdf", "attachment", fileName + ".pdf"); } } catch (JRException e) { e.printStackTrace(); } }