是否可以在 Spring boot 中将生成的 Excel 报告转换为PDF报告?
我想使用 Excel jrxml 文件在 Spring boot 中生成PDF碧玉报告,并尝试使用< em> jrxml 文件与生成 Excel 文件的方式相同。
但是新生成的.pdf文件与Excel报表相比在设计上有一些不规则之处,例如Excel的“ RemoveLineWhenBlank”选项在导出到.pdf并打印空白行时不起作用。
关联代码:
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(report);
InputStream inputStream = this.getClass().getResourceAsStream("report.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(inputStream);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null, dataSource);
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String fileName ="myreport.xlsx";
if (Downloadtype.equalsIgnoreCase("Excel")) {
JRXlsxExporter jrXlsxExporter = new JRXlsxExporter();
jrXlsxExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
jrXlsxExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
jrXlsxExporter.exportReport();
response.setHeader("Content Disposition","attachment;filename="report.xlsx");
response.setContentType("application/xlsx");
ServletOutputStream os = response.getOutputStream();
outputStream.writeTo(os);
os.flush();
} else {
JRPdfExporter jrPdfExporter = new JRPdfExporter();
jrPdfExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
jrPdfExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
jrPdfExporter.exportReport();
response.setHeader("Content-Disposition", "attachment; filename="report.pdf");
response.setContentType("application/pdf");
ServletOutputStream os = response.getOutputStream();
outputStream.writeTo(os);
os.flush();
}