4

我可以使用以下代码在单个 PDF 文件中打印多个报告,但它会为每个报告添加一个新页面。

JasperReport jreport1 = JasperCompileManager.compileReport("D:\\FTP\\JRXML\\PatientConsultantReport\\"+checkedReport+".jrxml");
JasperPrint jprint1 = JasperFillManager.fillReport(jreport1, new HashMap(), new JRResultSetDataSource(rs));
jprintlist.add(jprint1);
          .
         So ON
          .
          .
jprintlist.add(jprint5);

    JRExporter exporter = new JRPdfExporter();
                exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jprintlist);
                OutputStream output = new FileOutputStream(new File("D:\\FTP\\PDF\\VisitsSummaryReport.pdf"));
                exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, output);
                exporter.exportReport();

所以问题是:如何在 PDF 的单个页面上打印所有数据,而不是每个报告都有一个新页面?

4

4 回答 4

9
List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();

// Create multiple jasper prints and add to a list
HashMap<String, Object> params = new HashMap<String, Object>();
InputStream inputStream1 = this.getClass().getResourceAsStream("template1.jrxml");
JasperDesign jd1 = JRXmlLoader.load(inputStream1);
JasperReport jr1 = JasperCompileManager.compileReport(jd1);
JasperPrint jp1 = JasperFillManager.fillReport(jr1, params);
jasperPrintList.add(jp1);

InputStream inputStream2 = this.getClass().getResourceAsStream("template2.jrxml");
JasperDesign jd2 = JRXmlLoader.load(inputStream2);
JasperReport jr2 = JasperCompileManager.compileReport(jd2);
JasperPrint jp2 = JasperFillManager.fillReport(jr2, params);
jasperPrintList.add(jp2);

// Generating report using List<JasperPrint>
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new ByteArrayOutputStream()));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setCreatingBatchModeBookmarks(true);
exporter.setConfiguration(configuration);
exporter.exportReport();
于 2016-08-09T06:20:04.330 回答
3

这个怎么样?

 JRExporter exporter = new JRPdfExporter();

 exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream("c:/mipdf.pdf"));
 //The following is the important line
 exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, Arrays.asList(jasperPrint, jasperPrint));
 exporter.exportReport(); 

像魅力一样工作!

于 2014-04-02T17:58:43.087 回答
2

每个表生成一个 PDF 文件并使用itext将它们附加在一起。

更新:

这个 stackoverflow 帖子可能很有用。

jasper 报告中的多个表

于 2013-09-02T12:14:38.920 回答
0

你可以用这个。首先合并您的报告并导出为 pdf。

        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
        JasperPrint jasperPrint1 = JasperFillManager.fillReport(jasperReport1, 
        parameters, dataSource1);
        List<JRPrintPage> pages = jasperPrint1.getPages();
        for (int j = 0; j < pages.size(); j++) {
            JRPrintPage object = (JRPrintPage)pages.get(j);
            jasperPrint.addPage(object);
        }
        JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream)

这是常用的解决方案。

于 2019-11-20T10:20:54.603 回答