11/26/11

Merge multiple Jasper Reports in to Single Report

If you are working with Jasper Reports and JAVA you should meet with this problem


[jasperreports-questions] Merge multiple JasperPrint Objects

jeipack
Mon, 16 Apr 2007 04:55:31 -0700
Hi
I just want to show several JasperPrint Objects in only one JRViewer. Is
there a function to concat 2 or more JasperPrint Objects to one JasperPrint
Object? or something like that?

In pseudo code:
JasperPrint jp1 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));
JasperPrint jp2 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));
JasperPrint jp = jp1+jp2

jrviewer= new JRViewer(jp);


I hope its clear what i mean.
Thanks for your help!
jeipack




http://www.mail-archive.com/jasperreports-questions@lists.sourceforge.net/msg00728.html

a slimier question is [update] http://stackoverflow.com/questions/2666001/how-to-merge-two-pdf-documents-into-a-single-report-in-jasperreports/8278526#8278526

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 ..... Wolaah

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  

Questions are welcome

13 comments:

Networkදිසා said...

මම හරි ආසාවෙන් කියවපු දෙයක් තමයි OOP සිංහලෙන් පැහැදිලි කරල තිබුනු ලිපි ටික. ඒත් එ ටික නවත්තලා අළුත් මාතෘකාවකට බැහැල‍නෙ.අපි වගේ java වලට අළුත් අයට ඒ ලිපි සෙට් එක ගොඩක් වැදගත්.බරිද දිගටම ආයෙත් ඒ ගැන ලියන්න. මේක ඉල්ලීමක් විතරයි සහෝ......

Anonymous said...

Greetings! I've been reading your web site for some time now and finally got the courage to go ahead and give you a shout out from Porter Texas! Just wanted to mention keep up the fantastic work!

Here is my weblog :: breadthways

Anonymous said...

I'm truly enjoying the design and layout of your site. It's a very
easy on the eyes which makes it much more pleasant for
me to come here and visit more often. Did you hire out a developer to create your theme?
Fantastic work!

Stop by my website: account
My web page - series

Anonymous said...

When I initially commented I clicked the "Notify me when new comments are added" checkbox and now
each time a comment is added I get three emails with the same comment.
Is there any way you can remove me from that service? Appreciate it!


My web site ... Consignor

Anonymous said...

Hi there! Do you know if they make any plugins to protect against hackers?
I'm kinda paranoid about losing everything I've worked hard on.
Any tips?

Here is my site ... rid
my site > chemical stump

Anonymous said...

Today, I went to the beachfront with my kids. I found a sea shell and
gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear."
She put the shell to her ear and screamed. There was a hermit crab inside and
it pinched her ear. She never wants to go back! LoL
I know this is completely off topic but I had to tell someone!


Also visit my page packaging
Also see my website - profesionalna

Anonymous said...

Hello. I am wondering if you'd be interested in doing a website link swap? I notice your website: http://www.blogger.com/comment.g?blogID=3768508545659855687&postID=185329176962842324 and my blog are primarily based around the same topic. I'd really like to
switch links or possibly guest author a article for you.
Here is my personal email: bettyemackenzie@gmail.
com. Be sure to contact me if you're even remotely interested. Appreciate it.

Also visit my website: recovery

Anonymous said...

Hi there would you mind letting me know which
web host you're working with? I've loaded your blog in
3 completely different web browsers and I must say this blog loads a lot quicker then most.
Can you recommend a good internet hosting provider at a reasonable price?

Cheers, I appreciate it!

Feel free to surf to my blog post - data

Anonymous said...

Ι pаy a quick visit ԁaіly somе wеbsites anԁ blоgs to read сontent, hoωever
this wеb sitе рrеsents fеature baѕeԁ writing.


My web blog reputation management

Anonymous said...

This only works if the page dimensions are the same for both reports. It doesn't work if the first report is portrait and the second report is landscape.

Mikl said...

For the portait/landscape problem, I find this solution : http://ngjweb.wordpress.com/2011/12/09/fix-jasper-report-multi-oriented-pages/
Hope it will help you !

Admin said...

I'm truly experiencing the design.provide you with a yell out from Porter Texas! Just desired to bring up keep up the amazing work!
thanks.
Web Design in Bangladesh
Web Development in Bangladesh
SEO Services in Bangladesh

Fernando Zimmermann said...

Man, aweasome! works fine:

/**
* passar por parametro relatorios a serem concatenados
* referencia eh alterada
* @param relatorios
* @return
* @throws Exception
*/
public static byte[] juntarRelatorios(List relatorios) throws Exception {
//
JasperPrint primeiro = relatorios.remove(0);
for (JasperPrint jp : relatorios) {
List pages = jp.getPages();
for (JRPrintPage page : pages) {
primeiro.addPage(page);
}
}
//
return JasperExportManager.exportReportToPdf(primeiro);
}

Post a Comment