cu_bhavana Posted July 24, 2007 Share Posted July 24, 2007 Hi, I have two JasperPrint objects containing the report data generated by 2 separate JRXML files. Is there a way to merge them and view it using the ViewReport method of JasperViewer. If so can you please send me a code snippet? Thanks, Link to comment Share on other sites More sharing options...
contentengineer Posted July 24, 2007 Share Posted July 24, 2007 Sub-reports in the summary section of a new report. Set all other bands=0. Link to comment Share on other sites More sharing options...
C-Box Posted July 24, 2007 Share Posted July 24, 2007 Well perhaps the BATCH EXPORT Sample within the full Project (with demos) download can help you... but when I remember right, there where just some exporter usinig the JasperPrintList Parameter. In my environment I use the following code, but not sure if it works for you also. The problem is, that the orientation should not differ between the merging objects. But just take a look and feel free to modify if needed: Code:public DruckDokument mergeDruckDokumentList(ArrayList<DruckDokument> druckDokList) throws Exception { try { if (druckDokList != null && druckDokList.size() > 0) { long start = System.currentTimeMillis(); JasperPrint mergedJRPrint = new JasperPrint(); mergedJRPrint.setName("printedDocs"«»);// NOTE: fixed size A4 here for merging, as no other formats used currently!!! int pageHeight = 842; int pageWidth = 595; byte pageOrientation = JRReport.ORIENTATION_PORTRAIT; for (int i = 0; i < druckDokList.size(); i++) { DruckDokument aktDruckDok = druckDokList.get(i); JasperPrint jrPrint = null; switch (aktDruckDok.getFormat()) { case DruckDokument.FORMAT_JasperPrint: jrPrint = aktDruckDok.getJasperPrint(); break; case DruckDokument.FORMAT_JasperPrintXml: jrPrint = convertXmlToJasperPrint(aktDruckDok.getJasperPrintXml().getUncompressedBinary()); break; default: throw new Exception("Invalid DruckDokumentFormat at MergeDruckDokumentList!"«»); } // try to adjust to the current Page-Size/Orientation pageHeight = jrPrint.getPageHeight(); pageWidth = jrPrint.getPageWidth(); pageOrientation = jrPrint.getOrientation();// former times we had to merge the JRReportFonts also! But the were deprecated some new JasperVersions :«»-)// java.util.List<JRReportFont> fontList = jrPrint.getFontsList();// for (int j = 0; j < fontList.size(); j++) {// if (!mergedJRPrint.getFontsMap().containsKey(fontList.get(j).getName())) {// mergedJRPrint.addFont(fontList.get(j));// }// } /** @todo Test it!!!! 2005-11-04 because of new JasperReports Styles*/ Map mergeStyles = mergedJRPrint.getStylesMap(); Map aktStyles = jrPrint.getStylesMap(); Iterator<JRStyle> styleIt = aktStyles.values().iterator(); while (styleIt.hasNext()){ JRStyle aktStyle = styleIt.next(); if (!mergeStyles.keySet().contains(aktStyle.getName())){ mergedJRPrint.addStyle(aktStyle); } } java.util.List<JRPrintPage> pageList = jrPrint.getPages(); for (int j = 0; j < pageList.size(); j++) { mergedJRPrint.addPage(pageList.get(j)); } } mergedJRPrint.setPageHeight(pageHeight); mergedJRPrint.setPageWidth(pageWidth); mergedJRPrint.setOrientation(pageOrientation); byte[] jasperPrintXml = this.convertJasperPrintToXML(mergedJRPrint);// we always return a surrounding Object called "DruckDokument" that contains the actual JRPrint (or JasperPrintXML) return new DruckDokument(DruckDokument.FORMAT_JasperPrintXml, jasperPrintXml); } else { throw new Exception("No DruckDokument in DruckDokumentListe!"«»); } } catch (Exception ex) {// our own ExceptionHandler just formats the thrown ex throw ExceptionHandler.modifyException(ex); } } Just be sure to merge the Styles also! When I remember right, this must be done since the merged doc need to know ALL Styles also! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now