我面临一个问题,我有两个jrmxl文件。然后,我想加入一个pdf文件,但每个文件都加入一页。我在下面看到了一些提示,但是我不知道它们是否是最好的,因为我的第一个文件有3个波段:title,detail和summary。第二个有detail和summary。所以我想尽可能保留这种格式,因为摘要中有分页计数器。我已经尝试过了,但是第二页是空白的,高度为5厘米。列表页=新的ArrayList ();for (String caminhoRelatorio : caminhoRelatorios) { reportPath = JasperCompileManager.compileReport(caminhoRelatorio); reportPage = JasperFillManager.fillReport(reportPath, parameters, ds); pages.add(reportPage);}ByteArrayOutputStream baos = new ByteArrayOutputStream();JRPdfExporter jrPdfExporter = new JRPdfExporter();jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, pages);jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);jrPdfExporter.setParameter(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, Boolean.TRUE);jrPdfExporter.exportReport();那我该怎么办? (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 要将多个JRXML添加到一个报表/ PDF中,可以按照以下提到的方式进行:考虑下面的方法来生成带有2个JRXML的PDF报告,这些报告已添加到“ jrxmlFileNames”列表中public static void reportGenerator(String reportType, List<String> jrxmlFileNames,Datasource dataSource , String SwapFile){ JRConcurrentSwapFile swapFile = new JRConcurrentSwapFile(SwapFile, 102400 , 10); JRAbstractLRUVirtualizer virtualizer = new JRSwapFileVirtualizer(1000, swapFile, true); Map<String, JRAbstractLRUVirtualizer> parameters = new HashMap<String, JRAbstractLRUVirtualizer>(); parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); try { if (reportType.equalsIgnoreCase("PDF")) { try { JasperReport jreport1 = JasperCompileManager.compileReport(ReportGenerator.class.getResourceAsStream(jrxmlFileNames.get(0))); JasperPrint jprint1 = JasperFillManager.fillReport(jreport1, parameters, new JRBeanCollectionDataSource(dataSource.getDataSourceFor1())); JasperReport jreport2 = JasperCompileManager.compileReport(ReportGenerator.class.getResourceAsStream(jrxmlFileNames.get(1))); JasperPrint jprint2 = JasperFillManager.fillReport(jreport2, parameters, new JRBeanCollectionDataSource(dataSource.getDataSourceFor2())); List<JasperPrint> jprintlist = new ArrayList<JasperPrint>(); jprintlist.add(jprint1); jprintlist.add(jprint2); String fileName="TESTReport.pdf"; JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jprintlist); exporter.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, fileName); exporter.exportReport(); } catch(Exception e) { e.printStackTrace(); } } swapFile.dispose(); } catch(Exception e) { e.printStackTrace(); }}在上面的代码中,以下部分将帮助您添加多个JRXML。 List<JasperPrint> jprintlist = new ArrayList<JasperPrint>(); jprintlist.add(jprint1); jprintlist.add(jprint2); JRExporter exporter = new JRPdfExporter();exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jprintlist);希望能帮助到你! (adsbygoogle = window.adsbygoogle || []).push({});
09-26 12:30