我正在搜索一种使用 JRGraphics2DExporter
将报告导出为 JPG 的方法。
是否有可能使用JRGraphics2DExporter
来做到这一点?
最佳答案
您想要使用JRGraphics2DExporter
,但这也可以直接使用 JasperPrintManager
来完成
考虑每页使用多个图像 1 的代码示例
//Get my print, by filling the report
JasperPrint jasperPrint = JasperFillManager.fillReport(report, map,datasource);
final String extension = "jpg";
final float zoom = 1f;
String fileName = "report";
//one image for every page in my report
int pages = jasperPrint.getPages().size();
for (int i = 0; i < pages; i++) {
try(OutputStream out = new FileOutputStream(fileName + "_p" + (i+1) + "." + extension)){
BufferedImage image = (BufferedImage) JasperPrintManager.printPageToImage(jasperPrint, i,zoom);
ImageIO.write(image, extension, out); //write image to file
} catch (IOException e) {
e.printStackTrace();
}
}
如果您喜欢 1 个图像包含所有页面,则应在 jasperReport 标记上设置 isIgnorePagination="true"
关于java - JRGraphics2DExporter - 如何将报告导出为 JPG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41853392/