在做pdf帐票的时候,我们用的最多的open source工具应该就是JasperReports+iReport了。
iReport is the free,open source report designer for JasperReports. Create very sophisticated layouts containing charts,images,subreports,crosstabs and much more. Access your data through JDBC,tableModels,JavaBeans,XML,Hibernate,CSV,and custom sources. Then publish your reports as pdf,RTF,XLS,HTML,xhtml,text,DOCX,or OpenOffice.
JasperReports is the world's most popular open source reporting engine. It is entirely written in Java and it is able to use data coming from any kind of data source and produce pixel-perfect documents that can be vIEwed,printed or exported in a varIEty of document formats including HTML,pdf,Excel,OpenOffice and Word.
功能可以说是非常强大。
iReport 用来设计pdf模板,在java中通JasperReports来从DB取得数据并输出pdf帐票。
执行环境根据需要如下配置:
JasperReports Requirements | |||||||||||||||||
This table contains all the librarIEs that JasperReports may require,depending on the functionality required by JasperReports's parent application.
|
java取数据并输出pdf和Excel的代码片段:
Connection con = null; try { // jrxml path file jrxmlfile = new file("C:/reporttest/report.jrxml"); if(jrxmlfile.exists()){ // Compile jrxml JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlfile.getabsolutePath()); // Set parameter HashMap<String,Object> params = new HashMap<String,Object>(); params.put("KEY_ID",10); .... // Access DB Class.forname("org.postgresql.Driver"); con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/pdfTestDD","postgres","postgres"); // Write DB JasperPrint print = JasperFillManager.fillReport(jasperReport,params,con); // Set file name file pdf = new file("c:/report.pdf"); // Output pdf JasperExportManager.exportReportTopdffile(print,pdf.getabsolutePath()); // Output XLS file xls = new file("c:/reportXls.xls"); OutputStream output = new fileOutputStream(xls); JRXlsExporter exporterXLS = new JRXlsExporter(); exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT,print); exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,output); exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.FALSE); exporterXLS.exportReport(); }else{ System.out.println("jrxml is not exsit"); } } catch (Exception e) { e.printstacktrace(); } finally { if(con != null){ try { con.close(); } catch (sqlException e) { e.printstacktrace(); } } }总结
以上是内存溢出为你收集整理的PDF帐票工具:JasperReports+iReport全部内容,希望文章能够帮你解决PDF帐票工具:JasperReports+iReport所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)