当前位置:网站首页>Jasperreports - print PDF (project tool)
Jasperreports - print PDF (project tool)
2022-06-26 10:45:00 【Slightly drunk CC】
JasperReports —— Print PDF( Project tools )
【 Statement 】
- The material used in this article comes from the Internet ;
- This article is for learning purposes only ;
- Please refer to the blogger for details –> strive4free
One 、 Introduce
1.1 JasperReports principle
JasperReports Is a powerful 、 Flexible report generation tool , Able to display rich page content , And turn it into PDF,HTML, perhaps XML Format . The library consists entirely of Java It's written in , Can be used in a variety of Java Applications , Include J2EE,Web Generate dynamic content in the application . In general ,JasperReports Will combine Jaspersoft Studio( Template designer ) Use export PDF report form .
[ remarks : The picture is from the wisdom podcast ]
| Module name | explain |
|---|---|
| JRXML | Report filling template , The essence is a xml file |
| Jasper | from JRXML Binary file compiled from template , For code filling data |
| Jrprint | When the data is filled Jasper Object generated after , Used to output reports |
| Exporter | Report output management class , You can specify the format of the report to be output |
| PDF/HTML/XML | Report form |
1.2 Development process
Use JasperReports export pdf report form , The development process is as follows :
- Make report template
- Template compilation
- Structural data
- Fill in the data
- The output file
1.3 Template designer Jaspersoft Studio
Jaspersoft Studio Is a graphical report design tool , It's very convenient to design PDF Report template file ( It's really just a xml file ), combining JasperReports Use , You can render PDF file .
1.4 After designing the template, you can fill in the data
1.4.0 Add dependency
<!-- jasperreports rely on ( export PDF) -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.10.0</version>
<exclusions><!-- Built in dependent itext There is no... In the central warehouse , Need to be excluded -->
<exclusion>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--mysql Dependence -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!--junit4 Dependence -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
1.4.1 Design jrxml Template file

[ remarks : The picture is from the wisdom podcast ]
[ remarks : The picture is from the wisdom podcast ]
[ remarks : The picture is from the wisdom podcast ]
1.4.2 JDBC Fill data in data source mode
It will be designed demo1.jrxml Copy the file to the of the current project resources Under the table of contents ; Write unit tests ;
@Test
public void testReport_JDBC() throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/kanganhealth","root", "root");
//jrxml Template file path ( Designed in advance )
String jrxmlPath = "D:\\ideaProjects\\projects111\\jasperreports_test\\src\\main\\resources\\demo1.jrxml";
// from JRXML Binary file compiled from template , For code filling data ( Automatically created when file does not exist )
String jasperPath = "D:\\ideaProjects\\projects111\\jasperreports_test\\src\\main\\resources\\demo1.jasper";
// Compiling templates
JasperCompileManager.compileReportToFile(jrxmlPath,jasperPath);
// Structural data
Map paramsMap = new HashMap();
paramters.put("company","demo Test cases ");
// Fill in the data --- Use JDBC Data source filling
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperPath,paramsMap,connection);
// The output file
String pdfPath = "D:\\test.pdf";
JasperExportManager.exportReportToPdfFile(jasperPrint,pdfPath);
}
Output effect :
[ remarks : The picture is from the wisdom podcast ]
1.4.3 JavaBean Fill data in data source mode
Write unit test method output PDF file
@Test
public void testReport_JavaBean() throws Exception{
String jrxmlPath = "D:\\ideaProjects\\projects111\\jasperreports_test\\src\\main\\resources\\demo2.jrxml";
String jasperPath = "D:\\ideaProjects\\projects111\\jasperreports_test\\src\\main\\resources\\demo2.jasper";
// Compiling templates
JasperCompileManager.compileReportToFile(jrxmlPath,jasperPath);
// Structural data
Map paramters = new HashMap();
paramters.put("company","demo Testing company ");
List<Map> list = new ArrayList();
Map map1 = new HashMap();
map1.put("tName"," Induction medical package ");
map1.put("tCode","RZTJ");
map1.put("tAge","18-60");
map1.put("tPrice","500");
Map map2 = new HashMap();
map2.put("tName"," Sunshine parents elderly health examination ");
map2.put("tCode","YGBM");
map2.put("tAge","55-60");
map2.put("tPrice","500");
list.add(map1);
list.add(map2);
// Fill in the data --- Use JavaBean Data source filling
JasperPrint jasperPrint = JasperFillManager
.fillReport(jasperPath,paramters,new JRBeanCollectionDataSource(list));
// The output file
String pdfPath = "D:\\test.pdf";
JasperExportManager.exportReportToPdfFile(jasperPrint,pdfPath);
}
The test results 
[ remarks : The picture is from the wisdom podcast ]
边栏推荐
- Matrix fast power notes
- How to change the QR code material color of wechat applet
- Pit record_ TreeSet custom sorting results in less data loss
- Yarn package management tool
- Oracle11g 启动数据库时报错 ORA-27154: post/wait create failed
- Oracle sqlplus 查询结果显示优化
- 開發者,微服務架構到底是什麼?
- Renesas electronics launched a complete intelligent sensor solution for Internet of things applications
- Oracle11g reports an error when starting the database ora-27154: post/wait create failed
- MySQL project 8 summary
猜你喜欢

Linux下安装Mysql【详细】

What is in the method area - class file, class file constant pool, runtime constant pool

Using foreach to loop two-dimensional array

基础-MySQL

MySQL第十二次作业-存储过程的应用

【软件项目管理】期末复习知识点整理
![Installing MySQL under Linux [details]](/img/38/77be56c3ef3923ce4c4e5df4a96f41.png)
Installing MySQL under Linux [details]

About multi table query of MySQL

Establishment of smart dialogue platform for wechat official account

DBSCAN
随机推荐
Flutter and native communication (Part 1)
Notes - simple but adequate series_ KVM quick start
搜索引擎高级搜索方法记录
Global and Chinese market of aluminum sunshade systems 2022-2028: Research Report on technology, participants, trends, market size and share
Record the handling of oom problems caused by too many threads at one time
Idea remote debugger
开发者,微服务架构到底是什么?
Searchview click failure
Matrix fast power notes
Yarn package management tool
Oracle sqlplus query result display optimization
Oracle11g reports an error when starting the database ora-27154: post/wait create failed
Installer MySQL sous Linux [détails]
MySQL 8th job
Adaptiveavgpool2d does not support onnx export. Customize a class to replace adaptiveavgpool2d
1. sum of two numbers (leetcode topic)
CentOS安装Redis多主多从集群
String constant pool, class constant pool, and runtime constant pool
瑞萨电子面向物联网应用推出完整的智能传感器解决方案
MySQL第六次作业-查询数据-多条件