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

how to merge multiple pdf jasper reports into one?


novotny75

Recommended Posts

Hi,

 

I have about 6 JRXML files and I call JasperRunManager.runReportToPdf(...); on all 6 of them and have 6 resulting byte arrays. Naively I thought I could just add them all into one monster byte array but that doesn't seem to work. What is the proper way to merge all PDF byte arrays into one final PDF?

Also how can I eliminate blank pages? Some of the rendered PDF pages have an extra blank page.

 

Thanks, Jason

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

You can concatenate PDFs with iText (do a search to find sample code).  Or you can use JasperReports to export multimple reports into a single PDF, see the demo/samples/batchexport sample.

Blank pages are usually (but not necessarily) caused by empty bands or empty space at the bottom of report bands.

Regards,

Lucian

Link to comment
Share on other sites

  • 10 months later...

Lucianc et all,

Further of question, if I'd like to keep the bookmark level tree between the jrxmls, how can I make it,?

E.g. the AAA.jrxml hold an bookmark: AAAA; and the he BBB.jrxml hold an bookmark: BBBB; CCC.jrxml hold an bookmark: CCCC; if I'd like to make my bookmark tree like this way:

+AAAA

 ----BBBB

----CCCC

**************

from my idea, I have to use XSLT to concat the 3 jrxml to temp one and make the printing this way, but is there any low cost way?

 

Thanks in advance! 

ballackstone



Post Edited by suedwxg at 12/15/2009 06:38
Link to comment
Share on other sites

  • 1 month later...
  • 11 months later...

you know what, im gonna bump this thread as JasperReports have not been anything else but endless streak of agony and frustrations.

In your so called "batchexport sample", there are examples of how you can do it with "jrprint" files. But guess what, there is no, none, zero, zip documentation on how you would create those files. And before you voice your thought about "JasperFillManager.fillReport(jasperreport, params, con)", no, it DOES NOT create any "jrprint" files.

So here I am, with "batchexport sample", no way of knowing how i would merge these reports, and im frustrated beyond any limits.

 

edit: taking some of the above back. Make _damn_ sure your iReport and jasper jars are of the same version....version 4.0.0 actually produces ".jrprint" files when "fillReport" is used.

You can then go:

 

 

jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, con);

list.add(jasperPrint);

 

exp.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, list);

exp.setParameter(JRPdfExporterParameter.OUTPUT_FILE, new File("test.pdf"));

exp.exportReport();

This will export your report to a pdf.

 

If you put this into a for-loop with a query that updates itself, and fills report with new "jasperParameter"s, you will get several pages in your "test.pdf", with one page pr element/query.

I had it like this:

 

 

 

 

 

 

 

 

 

Code:
JRDesignQuery query = new JRDesignQuery();JasperPrint jasperPrint = null;Connection con = db.getConnection(); //my own class that creates a sql connectionList<Object> list = new ArrayList<Object>();JRPdfExporter exp = new JRPdfExporter();for(int k = 0; k < params.size(); k++){String query = "Select * from where somefield = ' " + params.get(k).get(3) + " ' ";query.setText (sqlQuery);JasperDesign jasperDesign = JRXmlLoader.load("GUI2.jrxml");jasperDesign.setQuery(query);jasperReport = JasperCompileManager.compileReport(jasperDesign); HashMap<String, String> jasperParameter = new HashMap<String, String>();jasperParameter.put("foo", params.get(k).get(2).toString()); //where "foo" is a field in your iReport .jrxml type file.jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, con);list.add(jasperPrint);exp.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, list);exp.setParameter(JRPdfExporterParameter.OUTPUT_FILE, new File("test.pdf"));exp.exportReport();

Post Edited by ojive at 01/27/2011 13:11
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...