es... Posted June 26, 2007 Share Posted June 26, 2007 Hi all!!I have two reports and i want to combine them in a single pdf. i wrote a simple code for that but unfortunately it doesnt work.it shows an empty small pdf page.Here is my code where am i doing wrong?How can i correct it.Please help me!Esra import java.util.HashMap; import net.sf.jasperreports.engine.JREmptyDataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRPrintPage;import net.sf.jasperreports.engine.JasperExportManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.util.JRLoader; public class TestOrientation{ public static void main(String[] args) { JasperPrint jasperPrintMain; JasperReport jasperReportMain;JasperPrint jasperPrintSub;JasperReport jasperReportSub;HashMap repParameters = new HashMap(); JREmptyDataSource dataSource = new JREmptyDataSource(); try { jasperReportMain = (JasperReport)JRLoader.loadObject("C:\main.jasper"); jasperPrintMain = JasperFillManager.fillReport( jasperReportMain, repParameters, dataSource); jasperReportSub=(JasperReport)JRLoader.loadObject("C:\sub.jasper"); jasperPrintSub = JasperFillManager.fillReport( jasperReportSub, repParameters, dataSource); JasperPrint jasperPrintAll = new JasperPrint(); for(int i=0;i<jasperPrintMain.getPages().size();i++){ jasperPrintAll.addPage((JRPrintPage)jasperPrintMain.getPages().get(i)); } for(int i=0;i<jasperPrintSub.getPages().size();i++) { jasperPrintAll.addPage((JRPrintPage)jasperPrintSub.getPages().get(i)); } JasperExportManager.exportReportToPdfFile(jasperPrintAll, "C:\testMerge.pdf"); } catch ( JRException e){ e.printStackTrace(); } }} Link to comment Share on other sites More sharing options...
aditya_gupta Posted June 27, 2007 Share Posted June 27, 2007 Hi, There is another way to do this. You can use Jasper_Print_List paramter of JRPdfExporterParamter class which accepts a collection object. The collection object is having all jasperPrint object. Following is the modified code, use this istead of your code. import java.util.HashMap; import net.sf.jasperreports.engine.JREmptyDataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRPrintPage;import net.sf.jasperreports.engine.JasperExportManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.util.JRLoader; public class TestOrientation{ public static void main(String[] args) { JasperPrint jasperPrintMain; JasperReport jasperReportMain; JasperPrint jasperPrintSub; JasperReport jasperReportSub; HashMap repParameters = new HashMap(); JREmptyDataSource dataSource = new JREmptyDataSource(); try { jasperReportMain = (JasperReport)JRLoader.loadObject("C:main.jasper"); jasperPrintMain = JasperFillManager.fillReport( jasperReportMain, repParameters, dataSource); jasperReportSub=(JasperReport)JRLoader.loadObject("C:sub.jasper"); jasperPrintSub = JasperFillManager.fillReport( jasperReportSub, repParameters, dataSource); ArrayList jasperPrintList = new ArrayList(); jasperPrintList.add(jasperPrintMain); jasperPrintList.add(jasperPrintSub); JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jasperPrintList); exporter.setParameter(JRPdfExporterParameter.OUTPUT_FILE, new File("C:testMerge.pdf")); exporter.exportReport(); } catch ( JRException e){ e.printStackTrace(); } } } AdityaPost edited by: aditya_gupta, at: 2007/06/27 06:29 Link to comment Share on other sites More sharing options...
es... Posted June 29, 2007 Author Share Posted June 29, 2007 oh..Really thanks for your help..i tried to do it,it successfully combines the files but it displays only 3 pages!!(the full document must be 38 pages:() Link to comment Share on other sites More sharing options...
aditya_gupta Posted June 29, 2007 Share Posted June 29, 2007 Hi, It works fine for me. I have total 550 pages in two reports. I am exporting it to html, pdf, xls, and rtf format. In all format it is working fine. Could you provide your code for reference. Aditya 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