Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge two pdf documents into a single report in JasperReports?

I am new to JasperReports. I can create a simple PDF document with Javabean datasource. In my project I have created two separate pdf document with separate javabean datasource. Now I want to merge both documents into a single document. Can anyone tell me how to merge both documents into single document using JasperReports?

like image 787
Kumar Avatar asked Apr 19 '10 08:04

Kumar


People also ask

How do I compile multiple PDF files into one?

Open Acrobat to combine files: Open the Tools tab and select "Combine files." Add files: Click "Add Files" and select the files you want to include in your PDF. You can merge PDFs or a mix of PDF documents and other files.

What is a PDF combiner?

Merging multiple files into one PDF lets you store and review them more easily. After you combine PDF files, simply sign in to organize individual pages or share your merged document.


1 Answers

unfortunately the solution is build a sub report and use the 2 different DataSource or what ever connection you used

but there is an easy way to get over with this question :D just simple no new reports ..... Voilà

ok lets do it

JasperPrint jp1 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));
JasperPrint jp2 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));

ok we have over 2 records ..lets take our first record jp1 and add jp2 content into it

List pages = jp2 .getPages();
for (int j = 0; j < pages.size(); j++) {
    JRPrintPage object = (JRPrintPage)pages.get(j);
    jp1.addPage(object);

}
JasperViewer.viewReport(jp1,false);

This work like a charm .. with couple of loops you can merge any number of report together .. without creating new reports

http://lnhomez.blogspot.com/2011/11/merge-multiple-jasper-reports-in-to.html

like image 141
Lahiru Nirmal Avatar answered Nov 01 '22 00:11

Lahiru Nirmal