How to show Multiple report on a single Pdf file on c# code.

Stimulsoft Reports.NET discussion
nicegaurav
Posts: 91
Joined: Mon Oct 15, 2012 10:03 am

How to show Multiple report on a single Pdf file on c# code.

Post by nicegaurav »

The scenario is ....
I have 2 or 3 report (.mrt files), want to show all report(.mrt files) on pdf when button click, and using c# code for this.
Using below mentioned code for displaying single report direct on the pdf.
StiReportResponse.ResponseAsPdf(this, report, false);
Now i have more than one report and want to show on single pdf file.

How can i do ... :?:

Thanks
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to show Multiple report on a single Pdf file on c# c

Post by HighAley »

Hello.

You could use next code to join your reports:

Code: Select all

            // Open and render report in Millimeters
            StiReport sourceReport = new StiReport();
            sourceReport.Load(@"d:\Millimeters.mrt");
            sourceReport.Compile();
            sourceReport.Render();

            // Now create report in Centimeters and copy rendered page from the first report
            StiReport report = new StiReport();
            report.NeedsCompiling = false;
            report.IsRendered = true;
            report.ReportUnit = StiReportUnitType.Centimeters;

            Stimulsoft.Report.Units.StiUnit newUnit = Stimulsoft.Report.Units.StiUnit.GetUnitFromReportUnit(report.ReportUnit);
            Stimulsoft.Report.Units.StiUnit oldUnit = Stimulsoft.Report.Units.StiUnit.GetUnitFromReportUnit(sourceReport.ReportUnit);
            bool needConvert = report.ReportUnit != sourceReport.ReportUnit;

            report.RenderedPages.Clear();
            foreach (StiPage page in sourceReport.CompiledReport.RenderedPages)
            {
                page.Report = report;
                page.NewGuid();
                if (needConvert) page.Convert(oldUnit, newUnit);
                report.RenderedPages.Add(page);
            }

            report.Show();
Thank you.
nicegaurav
Posts: 91
Joined: Mon Oct 15, 2012 10:03 am

Re: How to show Multiple report on a single Pdf file on c# c

Post by nicegaurav »

Thanks for ur kind reply..
But I have two different report (on different path) and i have to access both reports on a single pdf with multiple pages..

Is there any way to achieve this functionality.

Thanks
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to show Multiple report on a single Pdf file on c# c

Post by HighAley »

Hello.
nicegaurav wrote:Thanks for ur kind reply..
But I have two different report (on different path) and i have to access both reports on a single pdf with multiple pages..

Is there any way to achieve this functionality.
Here is a modified code from my previous message for your requirement:

Code: Select all

StiReport rep1 = new StiReport();
rep1.Load(@"f:\Support\Report1.mrt");
rep1.Compile();
rep1.Render();

StiReport rep2 = new StiReport();
rep2.Load(@"f:\Support\Report2.mrt");
rep2.Compile();
rep2.Render();

StiReport joinedReport = new StiReport();
joinedReport.NeedsCompiling = false;
joinedReport.IsRendered = true;
joinedReport.RenderedPages.Clear();

foreach (StiPage page in rep1.CompiledReport.RenderedPages)
{
    page.Report = joinedReport;
    page.NewGuid();
    joinedReport.RenderedPages.Add(page);
}

foreach (StiPage page in rep2.CompiledReport.RenderedPages)
{
    page.Report = joinedReport;
    page.NewGuid();
    joinedReport.RenderedPages.Add(page);
}

StiReportResponse.ResponseAsPdf(this, joinedReport, false);
Thank you.
nicegaurav
Posts: 91
Joined: Mon Oct 15, 2012 10:03 am

Re: How to show Multiple report on a single Pdf file on c# c

Post by nicegaurav »

Thanks a lot...

If we have 10 reports and displaying on single pdf on 10 pages, Can we set the page number on every page.
Like Page 1 of 10, Page 2 of 10 ........ page 10 of 10.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to show Multiple report on a single Pdf file on c# c

Post by HighAley »

Hello.

You could add next code to change text in the Text1 component:

Code: Select all

for (int i = 0; i < report.RenderedPages.Count; i++)
{
    foreach (StiComponent comp in report.RenderedPages[i].Components)
    {
        if (comp.Name == "Text1")
        {
            (comp as StiText).Text = "Page " + (i+1).ToString() + " of " + report.RenderedPages.Count.ToString();
        }
    }
}
Thank you.
nicegaurav
Posts: 91
Joined: Mon Oct 15, 2012 10:03 am

Re: How to show Multiple report on a single Pdf file on c# c

Post by nicegaurav »

Thanks ... :)
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to show Multiple report on a single Pdf file on c# c

Post by HighAley »

Hello.

We are always glad to help you.
Let us know if you need any additional help.

Thank you.
Vaibhav Tambolkar
Posts: 3
Joined: Wed Nov 19, 2014 10:08 am

Re: How to show Multiple report on a single Pdf file on c# c

Post by Vaibhav Tambolkar »

Hello,

On following below steps the font size of the resulting reports increased to such a level that the values in report are not visible properly.

The steps that I followed

1. Created a joinedreport and set its IsRendered to true and NeedCompiling to false.
2. Created individual reports(Each has a different mrt), compiled and rendered those.
3. Added rendered pages of the individual reports to the joinedreport.
4. Exported joinedreport to a pdf file.

Please let me know if I am missing something here.

Thanks,
Vaibhav
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to show Multiple report on a single Pdf file on c# c

Post by HighAley »

Hello.

To answer your question we need to see your code.
Please, send us a sample project that reproduces the issue.

Thank you.
Post Reply