public void writeToContent(OutputStream out) throws IOException { try { JasperExportManager.exportReportToPdfStream(report, out); } catch (JRException ex) { IOException ioe = new IOException(ex.getMessage()); ioe.initCause(ex); throw ioe; } } };
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(); } } }
@Override protected void checkLanguage(String language) throws JRException { if (!JRReport.LANGUAGE_JAVA.equals(language)) { throw new JRException(EXCEPTION_MESSAGE_KEY_EXPECTED_JAVA_LANGUAGE, new Object[] { language, JRReport.LANGUAGE_JAVA }); } }
public static JasperDesign loadJasperDesign(byte[] template) throws SchemaException{ try { byte[] reportTemplate = Base64.decodeBase64(template); InputStream inputStreamJRXML = new ByteArrayInputStream(reportTemplate); JasperDesign jasperDesign = JRXmlLoader.load(inputStreamJRXML); // LOGGER.trace("load jasper design : {}", jasperDesign); return jasperDesign; } catch (JRException ex){ throw new SchemaException(ex.getMessage(), ex.getCause()); } }
/** * 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(); } } }
@RequestMapping("/savepdf") public void dataEmployeePdf(HttpServletResponse response) { try { File file = new File("report/reportEmployee.jrxml"); String absolutePath = file.getAbsolutePath(); InputStream input = new FileInputStream(new File(absolutePath)); JasperReport jasperReport = JasperCompileManager.compileReport(input); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null); JasperExportManager.exportReportToPdfStream(jasperPrint,response.getOutputStream()); } catch (JRException ex) { ex.getMessage(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
protected void checkLanguage(String language) throws JRException { if (!JRReport.LANGUAGE_JAVA.equals(language)) { throw new JRException( "Language \"" + language + "\" not supported by this report compiler.\n" + "Expecting \"java\" instead." ); } }
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(); } }
public void uploadJrxmlFile(String filename, String fileContent) throws ReportingException { try { fileUploaderService.uploadJrxmlFile(filename, fileContent); } catch (JRException e) { log.error(e.getMessage(), e); throw new ReportingException(e.getMessage(), e); } catch (ReportingException e) { log.error(e.getMessage(), e); throw e; } }
protected void checkLanguage(String language) throws JRException { if (!JRReport.LANGUAGE_JAVA.equals(language)) { throw new JRException( "Language \"" + language + "\" not supported by this report compiler.\n" + "Expecting \"java\" instead." ); } }
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(); } }
/** * 打印报表 * @param jasperFile jasper文件 * @param params 模板所需的参数 * @param dataSource 模板所需的数据源 * @param <T> 数据源泛型 */ public static <T> void print(String jasperFile, Map<String, Object> params, List<T> dataSource) { try { JasperPrintManager.printReport(getJasperPrintFile(jasperFile, params, dataSource), true); } catch (JRException e) { logger.error(e.getMessage()); } }
@Override protected void checkLanguage(String language) throws JRException { if (!JRReport.LANGUAGE_JAVA.equals(language)) { throw new JRException(EXCEPTION_MESSAGE_KEY_EXPECTED_JAVA_LANGUAGE, new Object[] { language, JRReport.LANGUAGE_JAVA }); } }
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(); } } }
try { String shopName = jComboBox1.getSelectedItem().toString(); String actionCode = jComboBox2.getSelectedItem().toString(); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("storeName", shopName); map.put("actionCode", actionCode); URL reportFileURL = getClass().getResource("../ireps/AccessCounter.jrxml"); File reportFile = new File(reportFileURL.toURI()); JasperDesign jasperDesign = JRXmlLoader.load(reportFile); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, con); JasperViewer jv = new JasperViewer(jasperPrint); JDialog viewer = new JDialog(this, "Batch Report", true); viewer.setBounds(jv.getBounds()); viewer.getContentPane().add(jv.getContentPane()); viewer.setResizable(true); viewer.setIconImage(jv.getIconImage()); viewer.setVisible(true); } catch (JRException exc) { System.out.println(exc.getMessage()); } catch (URISyntaxException exs) { System.out.println(exs.getMessage()); }
/** * Reads a character from the stream. * @throws IOException if any I/O error occurs * @throws JRException if end of stream has been reached */ private char getChar() throws IOException, JRException { // end of buffer, fill a new buffer if (position + 1 > bufSize) { bufSize = reader.read(buffer); position = 0; if (bufSize == -1) throw new JRException("No more chars"); } return buffer[position++]; }
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.
try { String shopName = jComboBox1.getSelectedItem().toString(); String actionCode = jComboBox2.getSelectedItem().toString(); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("storeName", shopName); map.put("actionCode", actionCode); URL reportFileURL = getClass().getResource("../ireps/AccessCounter.jrxml"); File reportFile = new File(reportFileURL.toURI()); JasperDesign jasperDesign = JRXmlLoader.load(reportFile); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, con); JasperViewer jv = new JasperViewer(jasperPrint); JDialog viewer = new JDialog(this, "Batch Report", true); viewer.setBounds(jv.getBounds()); viewer.getContentPane().add(jv.getContentPane()); viewer.setResizable(true); viewer.setIconImage(jv.getIconImage()); viewer.setVisible(true); } catch (JRException exc) { System.out.println(exc.getMessage()); } catch (URISyntaxException exs) { System.out.println(exs.getMessage()); }
public void moveFirst() throws JRException { if (document == null) throw new JRException("document cannot be null"); if (selectExpression == null) throw new JRException("selectExpression cannot be null"); currentNode = null; currentNodeIndex = -1; nodeListLength = 0; nodeList = xPathExecuter.selectNodeList(document, selectExpression); nodeListLength = nodeList.getLength(); }