In Jasper report how to create report pdf using subreport for XML datasource.

4

I used the following link http://community.jaspersoft.com/wiki/use-subreport-report-which-connecte...

and created a main report containing 2 subreports in iReport 5.5.*. Now in Java I'm not sure how to use subreports but my code is as follows:

 

JasperPrint print = new JasperPrint();
JRPdfExporter exporter = new JRPdfExporter();
JasperDesign design, design1;
JasperReport report, report1;
JasperReport jasperReport;
JasperDesign jd1;


jd1 = JRXmlLoader.load("C:/Users/bferrao/Desktop/jasper/TransactionReport_subreport1.jrxml");
jasperReport = JasperCompileManager.compileReport(jd1);

Map parameters = new HashMap();
parameters.put("Subreport_1", jasperReport);

design = JRXmlLoader.load("C:/Users/bferrao/Desktop/jasper/TransactionReport_subreport2.jrxml");
report = JasperCompileManager.compileReport(design);
parameters.put("Subreport_2", report);

Document document = JRXmlUtils.parse(new File("C:/Users/bferrao/Desktop/jasper/TransactionReport.xml"));
parameters.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);

JRXmlDataSource jrxmlds = new JRXmlDataSource(new File("C:/Users/bferrao/Desktop/jasper/TransactionReport.xml"), "/Report");
design1 = JRXmlLoader.load("C:/Users/bferrao/Desktop/jasper/TransactionReport.jrxml");
report1 = JasperCompileManager.compileReport(design1);
JasperFillManager.fillReportToFile(report1, "C:/Users/bferrao/Desktop/jasper/master_report.jrprint", parameters, jrxmlds);

exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "D:\\temp\\Report3.pdf");
exporter.exportReport();

bosgr8's picture
20
Joined: Mar 28 2014 - 3:08am
Last seen: 5 months 3 weeks ago

0 Answers:

No answers yet
Feedback
randomness