Spring Boot integrates JasperReport to generate documents

Due to work needs, it is necessary to realize the back-end dynamic filling of data according to the template to generate PDF documents. Through technology selection, Ireport5.6 is used to design the template, and the JasperReports5.6 tool library is used to call rendering to generate PDF documents.

1. Use Ireport designer 5.6 to design templates

It is inconvenient to say more about the use of ireport due to time constraints. After the design is completed, compile it to generate a jasper file, and then place a copy of it in the project jasper directory for access to the file.

2. Introduce dependency packages into the Spring Boot project

<!-- jasperreports-->
<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.0.0</version>
</dependency>
<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports-fonts</artifactId>
    <version>6.0.0</version>
</dependency>
<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itextpdf</artifactId>
    <version>5.5.0</version>
</dependency>
<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itext-pdfa</artifactId>
    <version>5.5.0</version>
</dependency>
<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itext-asian</artifactId>
    <version>5.2.0</version>
</dependency>
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>2.4.11</version>
</dependency>

3. Customize spring mvc universal export PDF view class PdfReportView (inherited from AbstractView)

4. Spring mvc calling case

5. Solve the problem of Song Dynasty rendering under Linux

1. Create a new jasperreports_extension.properties file in the src/main/resources path with the following content:

2. Create a new fonts directory under the src/main/resources path and create a new fonts.xml file

3. Put the Songti font file simsun.ttf in the src/main/resources/fonts directory

4. The online (linux environment) preview effect is as follows:

If reprinted, please indicate the source: Open Source Byte   https://sourcebyte.vip/article/335.html

 

Guess you like

Origin blog.csdn.net/qq_35634154/article/details/132795534