当前位置:网站首页>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 ]
边栏推荐
- About multi table query of MySQL
- 【LeetCode】59. Spiral matrix II
- MySQL第九次作业-连接查询&子查询
- Enter a positive integer with no more than 5 digits, and output the last digit in reverse order
- Common interview questions of binary tree
- 六月集训(第26天) —— 并查集
- Idea remote debugger
- CentOS安装Redis多主多从集群
- 瑞萨电子面向物联网应用推出完整的智能传感器解决方案
- Blog article index summary -- Software Engineering
猜你喜欢

OpenCV图像处理-灰度处理

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

Win10 start FTP service and set login authentication

Concise course of probability theory and statistics in engineering mathematics second edition review outline

DataBinding使用与原理分析

瑞萨电子面向物联网应用推出完整的智能传感器解决方案

How to change the QR code material color of wechat applet

Quantitative investment learning - Introduction to classic books

MySQL 12th job - Application of stored procedure

MySQL第十四次作业--电子商城项目
随机推荐
Pytest configuration file
利用foreach循环二维数组
Express (I) - easy to get started
MySQL第八次作业
Global and Chinese market of electronic pet door 2022-2028: Research Report on technology, participants, trends, market size and share
Notes - simple but adequate series_ KVM quick start
Problems encountered in the application and development of Hongmeng and some roast
3行3列整形二维数组,求对角之和
[difficult and miscellaneous diseases] @transitional failure summary
工程数学概率论统计简明教程第二版复习大纲
MySQL第十次作业-视图
Linux下安裝Mysql【詳細】
String constant pool, class constant pool, and runtime constant pool
Based on Zeng Shen's explanation, the line segment tree is studied again one
Basic MySQL
What are the symbolic and direct references of the JVM
Concise course of probability theory and statistics in engineering mathematics second edition review outline
Hcia-dhcp experiment
MySQL第五章总结
MySQL第十一作業-視圖的應用