本文介绍了JRGraphics2DExporter-如何将报告导出为JPG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在用 JRGraphics2DExporter 搜索一种将报告导出为JPG的方法.

I'm searching a method with JRGraphics2DExporter to export report as JPG.

使用 JRGraphics2DExporter 可以做到这一点吗?

Is there any kind of possibility to do that with JRGraphics2DExporter?

推荐答案

您要使用 JRGraphics2DExporter ,但是也可以直接使用 JasperPrintManager

You want to use the JRGraphics2DExporter, but this can also be done directly using the JasperPrintManager

示例的代码,每页包含多张图片1

Example of code contemplenting multiple images 1 for every page

//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"

If you like 1 image with all the pages, you should set the isIgnorePagination="true" on the jasperReport tag

这篇关于JRGraphics2DExporter-如何将报告导出为JPG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 10:31