Jump to content
We've recently updated our Privacy Statement, available here ×

what is wrong in this code?(combining reports)


es...

Recommended Posts

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

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

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();

 

}

 

 

 

}

 

}

 

 

 

Aditya

Post edited by: aditya_gupta, at: 2007/06/27 06:29

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...