PDF帐票工具:JasperReports+iReport

PDF帐票工具:JasperReports+iReport,第1张

概述在做PDF帐票的时候,我们用的最多的open source工具应该就是JasperReports+iReport了。 iReport is the free, open source report designer for JasperReports. Create very sophisticated layouts containing charts, images, subreports,

在做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.

JRE

Java Runtime Environment 5.0 or higher

Commons

Jakarta Commons BeanUtils Component (version 1.8.0 or later)
http://jakarta.apache.org/commons/beanutils/ Jakarta Commons Collections Component (version 2.1.1 or later)
http://jakarta.apache.org/commons/collections/ Jakarta Commons Javaflow (SandBox version)
http://jakarta.apache.org/commons/sandbox/javaflow/ Jakarta Commons Logging Component (version 1.0.4 or later)
http://jakarta.apache.org/commons/logging/

JRXML

JAXP 1.1 XML Parser Jakarta Commons Digester Component (version 1.7 or later)
http://jakarta.apache.org/commons/digester/ One of the following for report compilation,depending on the report compiler used: Eclipse JDT Java Compiler (recommended)
http://www.eclipse.org/jdt/ JDK 5.0 or higher Jikes Compiler http://jikes.sourceforge.net Groovy (version 1.5.5 or later) http://groovy.codehaus.org BeanShell (version 2.0 beta 4 or later) http://www.beanshell.org

JDBC

JDBC 2.0 Driver

pdf

iText - Free Java-pdf library by Bruno LowagIE and Paulo Soares (version 2.1.7 or later) http://www.lowagie.com/iText/

XLS

Jakarta POI (version 3.6 or later) http://jakarta.apache.org/poi/ JExcelAPI (version 2.6.10 or later) http://jexcelapi.sourceforge.net/

Charts

JFreeChart (1.0.12 or later) http://www.jfree.org/jfreechart/ JCommon (1.0.15 or later) - required by JFreeChart http://www.jfree.org/jcommon/ Batik SVG Toolkit (1.7 or later) - required when rendering charts as SVG http://xmlgraphics.apache.org/batik/

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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1179471.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存