Springboot整合JasperReport报表

tech2025-07-26  10

String path = this.getClass().getResource("/jasperreport/"+reportName+".jrxml").getPath(); File file = new File(path); String parentPath = file.getParent(); String jrxmlDestSourcePath = parentPath+"/"+reportName+".jasper"; JasperCompileManager.compileReportToFile(path, jrxmlDestSourcePath); InputStream isRef = new FileInputStream(new File(jrxmlDestSourcePath)); ServletOutputStream sosRef = response.getOutputStream(); response.setContentType("application/pdf"); JasperRunManager.runReportToPdfStream(isRef,sosRef,new HashMap(), new JREmptyDataSource()); sosRef.flush(); sosRef.close();

jar

<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>
最新回复(0)