jasperreports一次打印多张报表怎么实现
答案:1 悬赏:20 手机版
解决时间 2021-11-23 21:32
- 提问者网友:临风不自傲
- 2021-11-23 14:12
jasperreports一次打印多张报表怎么实现
最佳答案
- 五星知识达人网友:你可爱的野爹
- 2021-11-23 14:43
1、若是采用bean作为数据源,可将多个条数据组装成List:
List list = new ArrayList();
list.add(xxx);
list.add(xxx);
......
2、将List装入中:
JRDataSource source =new JRBeanCollectionDataSource(list)
3、初始化jasperReport 对象:
JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile("你的.jasper文件路径");
4、构建JasperPrint 对象,将jasperReport 对象,source数据源填充到report中:
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null, source);
5、获取打印机列表:
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.PNG;
PrintService[] printService = PrintServiceLookup.lookupPrintServices(flavor, pras);
6、指定打印机打印:
for (PrintService p : printService) {
if("指定的打印机名称".equals(p.getName())){
JRAbstractExporter je=new JRPrintServiceExporter();
//传入jasperPrint对象
je.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
je.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE,p);
je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,false);
je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,false);
je.exportReport();
}
}
List
list.add(xxx);
list.add(xxx);
......
2、将List装入中:
JRDataSource source =new JRBeanCollectionDataSource(list)
3、初始化jasperReport 对象:
JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile("你的.jasper文件路径");
4、构建JasperPrint 对象,将jasperReport 对象,source数据源填充到report中:
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null, source);
5、获取打印机列表:
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.PNG;
PrintService[] printService = PrintServiceLookup.lookupPrintServices(flavor, pras);
6、指定打印机打印:
for (PrintService p : printService) {
if("指定的打印机名称".equals(p.getName())){
JRAbstractExporter je=new JRPrintServiceExporter();
//传入jasperPrint对象
je.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
je.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE,p);
je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,false);
je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,false);
je.exportReport();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯