net.sf.jasperreports.engine.JasperRunManager Java Examples
The following examples show how to use
net.sf.jasperreports.engine.JasperRunManager.
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: JasperApp.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
/** * */ public void run() throws JRException { long start = System.currentTimeMillis(); //Preparing parameters Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg"); MediaTracker traker = new MediaTracker(new Panel()); traker.addImage(image, 0); try { traker.waitForID(0); } catch (Exception e) { e.printStackTrace(); } Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("ReportTitle", "The First Jasper Report Ever"); parameters.put("MaxOrderID", 10500); parameters.put("SummaryImage", image); JasperRunManager.runReportToPdfFile("build/reports/FirstJasper.jasper", parameters, getDemoHsqldbConnection()); System.err.println("PDF running time : " + (System.currentTimeMillis() - start)); }
Example #2
Source File: ReportGenerationServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * @see org.kuali.kfs.sys.batch.service.ReportGenerationService#generateReportToOutputStream(java.util.Map, java.lang.Object, * java.lang.String, java.io.ByteArrayOutputStream) */ public void generateReportToOutputStream(Map<String, Object> reportData, Object dataSource, String template, ByteArrayOutputStream baos) { ClassPathResource resource = getReportTemplateClassPathResource(template.concat(ReportGeneration.DESIGN_FILE_EXTENSION)); if (resource == null || !resource.exists()) { throw new IllegalArgumentException("Cannot find the template file: " + template.concat(ReportGeneration.DESIGN_FILE_EXTENSION)); } try { if (reportData != null && reportData.containsKey(ReportGeneration.PARAMETER_NAME_SUBREPORT_TEMPLATE_NAME)) { Map<String, String> subReports = (Map<String, String>) reportData.get(ReportGeneration.PARAMETER_NAME_SUBREPORT_TEMPLATE_NAME); String subReportDirectory = (String) reportData.get(ReportGeneration.PARAMETER_NAME_SUBREPORT_DIR); compileSubReports(subReports, subReportDirectory); } String designTemplateName = template.concat(ReportGeneration.DESIGN_FILE_EXTENSION); InputStream jasperReport = new FileInputStream(compileReportTemplate(designTemplateName)); JRDataSource jrDataSource = JasperReportsUtils.convertReportData(dataSource); JasperRunManager.runReportToPdfStream(jasperReport, baos, decorateReportData(reportData), jrDataSource); } catch (Exception e) { LOG.error(e); throw new RuntimeException("Fail to generate report.", e); } }
Example #3
Source File: ReportGenerationServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * The dataSource can be an instance of JRDataSource, java.util.Collection or object array. * * @see org.kuali.kfs.sys.batch.service.ReportGenerationService#generateReportToPdfFile(java.util.Map, java.lang.Object, java.lang.String, * java.lang.String) */ public void generateReportToPdfFile(Map<String, Object> reportData, Object dataSource, String template, String reportFileName) { ClassPathResource resource = getReportTemplateClassPathResource(template.concat(ReportGeneration.DESIGN_FILE_EXTENSION)); if (resource == null || !resource.exists()) { throw new IllegalArgumentException("Cannot find the template file: " + template.concat(ReportGeneration.DESIGN_FILE_EXTENSION)); } try { if (reportData != null && reportData.containsKey(ReportGeneration.PARAMETER_NAME_SUBREPORT_TEMPLATE_NAME)) { Map<String, String> subReports = (Map<String, String>) reportData.get(ReportGeneration.PARAMETER_NAME_SUBREPORT_TEMPLATE_NAME); String subReportDirectory = (String) reportData.get(ReportGeneration.PARAMETER_NAME_SUBREPORT_DIR); compileSubReports(subReports, subReportDirectory); } String designTemplateName = template.concat(ReportGeneration.DESIGN_FILE_EXTENSION); InputStream jasperReport = new FileInputStream(compileReportTemplate(designTemplateName)); JRDataSource jrDataSource = JasperReportsUtils.convertReportData(dataSource); reportFileName = reportFileName + ReportGeneration.PDF_FILE_EXTENSION; File reportDirectory = new File(StringUtils.substringBeforeLast(reportFileName, File.separator)); if(!reportDirectory.exists()) { reportDirectory.mkdir(); } JasperRunManager.runReportToPdfStream(jasperReport, new FileOutputStream(reportFileName), decorateReportData(reportData), jrDataSource); } catch (Exception e) { LOG.error(e); throw new RuntimeException("Fail to generate report.", e); } }