【问题标题】:Best way to create a merged JasperReport创建合并 JasperReport 的最佳方法
【发布时间】:2018-07-18 14:31:33
【问题描述】:

在我的 Java Web 应用程序中,我确实生成了一份报告,每个客户检测到一个页面。

我创建了一个 JasperReport,如果客户列表超过 1 个,我想合并生成的报告。

这是我的代码:

if(myList.size()==1) {
        JasperPrint jp = reportGenerated(myList.get(0).getCustomer());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        JasperExportManager.exportReportToPdfStream(jp, bos);

        return bos.toByteArray();
    }else {
        for(Object s: myList) {
                                jasperPrints.add(reportGenerated(s.getCustomer()));
            }
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 

        JRPdfExporter exporter = new JRPdfExporter();
        exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrints));
        exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("pdf/lettera.pdf")); 
        SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();

        configuration.setCreatingBatchModeBookmarks(true); 
        exporter.setConfiguration(configuration);
        exporter.exportReport();


    }

我想获取合并后的PDF,但是在ByteArrayOutputStream中找不到导出JasperPrint列表的功能。

有什么建议吗?

【问题讨论】:

  • 无需连接报表输出。改为更改报告以获取客户集合。有报表控制分页,你会发现所有客户的输出都是自动连接的。

标签: java jasper-reports export-to-pdf


【解决方案1】:

尝试改变:

exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("pdf/lettera.pdf"))

与:

exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(bos)); 

并添加return语句:

 return bos.toByteArray();

我认为这个解决方案可以帮助你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    • 2023-03-26
    • 2013-01-22
    • 2020-06-21
    • 1970-01-01
    相关资源
    最近更新 更多