Merge multiple reports into one

Stimulsoft Reports.JAVA discussion
Post Reply
Lezenn
Posts: 10
Joined: Thu Jul 07, 2022 12:42 pm

Merge multiple reports into one

Post by Lezenn »

Hi,

I'd need to merge multiple reports into one.
I found this topic: viewtopic.php?t=35102 about merging reports from code in C#.

But if I try it in Java,

Code: Select all

reportPart.getCompiledReport();
returns null. IntelliJ shows me that

Code: Select all

reportPart.Compile();

does nothing (empty method).

How can I do it in Java?
Lech Kulikowski
Posts: 4754
Joined: Tue Mar 20, 2018 5:34 am

Re: Merge multiple reports into one

Post by Lech Kulikowski »

Hello,

Please check the following topic:
viewtopic.php?f=27&t=56842

Thank you.
Lezenn
Posts: 10
Joined: Thu Jul 07, 2022 12:42 pm

Re: Merge multiple reports into one

Post by Lezenn »

Hi,

Thank for your reply.
I have this code:

Code: Select all

            StiReport reportCombine = new StiReport();
            reportCombine.setReportUnit(StiReportUnitType.Centimeters);
            reportCombine.render();
            reportCombine.getRenderedPages().clear();

            for (/* Datas to inject in each subreport */) {

                StiReport subReport = StiSerializeManager.deserializeReport(this.getClass().getClassLoader().getResourceAsStream("my_template.mrt"));

                subReport.setCalculationMode(StiCalculationMode.Interpretation);
                injecterDonnees(releve, subReport); // Puts datas into the report
                subReport.render();

                for (StiPage page : simpleReleve.getRenderedPages()) {
                    reportCombine.getRenderedPages().add(page);
                }
            }

            StiExportManager.exportPdf(reportCombine, sortieDocument);
Stimulsoft crashes on the reportCombine.render() call, on an ArrayIndexOutOfBoundException Index 0, Size 0.
Am I doing it wrong ?
Vadim
Posts: 319
Joined: Tue Apr 23, 2013 11:23 am

Re: Merge multiple reports into one

Post by Vadim »

Hello.

Instead new StiReport(); please use StiReport.newInstance()
Lezenn
Posts: 10
Joined: Thu Jul 07, 2022 12:42 pm

Re: Merge multiple reports into one

Post by Lezenn »

Hi,

Thanks for your reply. The rendering does not crash anymore. Now I have to find out why I get a single blank page :)
Vadim
Posts: 319
Joined: Tue Apr 23, 2013 11:23 am

Re: Merge multiple reports into one

Post by Vadim »

Hello.

Maybe you got empty simpleReleve.getRenderedPages()
Please check reportCombine.getRenderedPages() filling before PDF export.
Lezenn
Posts: 10
Joined: Thu Jul 07, 2022 12:42 pm

Re: Merge multiple reports into one

Post by Lezenn »

It seems like I get my simpleReports without any components.
Lezenn
Posts: 10
Joined: Thu Jul 07, 2022 12:42 pm

Re: Merge multiple reports into one

Post by Lezenn »

So,

My solution is:

Code: Select all

            StiReport reportCombine = StiReport.newInstance();
            reportCombine.setReportUnit(StiReportUnitType.Centimeters);
            reportCombine.getRenderedPages().clear();

            for (/* for each sub report data */) {

                StiReport simpleReleve = StiSerializeManager.deserializeReport(
                        Objects.requireNonNull(this.getClass().getClassLoader().getResourceAsStream("template.mrt"))
                );

                simpleReleve.setCalculationMode(StiCalculationMode.Interpretation);
                injecterDonnees(subReportData, simpleReleve); // Put sub report data
                simpleReleve.render();

		// Report merging
                for (StiPage page : simpleReleve.getRenderedPages()) {
                    if (!reportCombine.getRenderedPages().add(page)) {
                        log.warn("Une page n'a pu être ajoutée au document final.");
                    }
                }
            }

            StiExportManager.exportPdf(reportCombine, sortieDocument);
It works fine. Thank for your help !
Lech Kulikowski
Posts: 4754
Joined: Tue Mar 20, 2018 5:34 am

Re: Merge multiple reports into one

Post by Lech Kulikowski »

Hello,

You are welcome.
Post Reply