Printing multiple reports in one tab

OlaOla
edited 2:28AM in FastReport .NET
My problem is the following:

I have several different reports that I am trying to get to print in one and the same tab in my browser. I found this page on the FAQ:
https://www.fast-report.com/en/faq/18/264/
which describes a general way to do so.

In my case, the reports I am trying to merge into one are fairly different consisting of dissimilar data. So I loop through them all, filling them with their data, and then at the end I do the following code:
                        webReport.ReportFile = GetReportPath() + result.ReportFile;
                        result.DataSetToRegister.ForEach(ds => webReport.Report.RegisterData(ds));
                        webReport.Report.Load(GetReportPath() + result.ReportFile);
                        webReport.Report.Prepare(true);

My problem is that after having looped through all my reports, the only one that appears on my web page is the final one - it seems the previous reports are overwritten by the next following report, one after one.

Can anyone spot a mistake I've made, or come up with another helpful suggestion?

Comments

  • edited 2:28AM
    Ola wrote: »
    My problem is the following:

    I have several different reports that I am trying to get to print in one and the same tab in my browser. I found this page on the FAQ:
    https://www.fast-report.com/en/faq/18/264/
    which describes a general way to do so.

    In my case, the reports I am trying to merge into one are fairly different consisting of dissimilar data. So I loop through them all, filling them with their data, and then at the end I do the following code:
                            webReport.ReportFile = GetReportPath() + result.ReportFile;
                            result.DataSetToRegister.ForEach(ds => webReport.Report.RegisterData(ds));
                            webReport.Report.Load(GetReportPath() + result.ReportFile);
                            webReport.Report.Prepare(true);
    

    My problem is that after having looped through all my reports, the only one that appears on my web page is the final one - it seems the previous reports are overwritten by the next following report, one after one.

    Can anyone spot a mistake I've made, or come up with another helpful suggestion?

    I don't think you can .ForEach to RegisterData(), it will wipe and replace the prior set.
    I would first try to .RegisterData(ds, ds.NAME?) so they are each named differently
    But considering you are going to have different names, this will probably break your report
    I think you need to combine the datasets into one first then call .RegisterData
    https://stackoverflow.com/questions/1227805...e-using-c-sharp

  • OlaOla
    edited 2:28AM
    I think you need to combine the datasets into one first then call .RegisterData
    https://stackoverflow.com/questions/1227805...e-using-c-sharp

    The reports I am trying to combine have different datasets with very different values in each, so I don't think they could be combined into one dataset, at least not the way you suggest in the linked page. Does that mean it's not possible to combine the various reports into one pdf file?
  • edited February 2019
    wrote:
    The reports I am trying to combine have different datasets with very different values in each, so I don't think they could be combined into one dataset, at least not the way you suggest in the linked page.

    you must follow the instruction in https://www.fast-report.com/en/faq/18/264/
    1. with report object
    a. load frx file
    b. register data
    c. prepare report, it will generate report and the result is called 'PreparedPages'
    d. register data again
    e. prepare report with append = true
    var report = new report();
    report.load("frx file");
    foreach (var item in DataSetToRegister)
    {
      report.registerdata(item);
      report.prepare(true);
    }
    

    2.webreport object
    a.attach report object to webreport
    b.webreport object is cached
    c.when end user is requesting report page, report (from cache) is exported to html
    var wr= new webreport();
    wr.report = report;
    
    wrote:
    Does that mean it's not possible to combine the various reports into one pdf file?
    you dont need webreport object here, just report object and outputted to pdf object
                    using (FastReport.Report report = new FastReport.Report())
                    {
                        string frxFile = Path.Combine(_env.ContentRootPath, "frx file");
                        string fileName = "report.pdf";
                        report.Load(frxFile);
                        report.RegisterData(dataTable, "NorthWind");
                        report.Prepare();
                        using (MemoryStream ms = new MemoryStream())
                        {
                            using (FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport())
                            {
                                pdfExport.Export(report, ms);
                            }
                            ms.Position = 0;
                            return new FileContentResult(ms.ToArray(), "application/pdf") { FileDownloadName = fileName };
                        }
                    }
    
  • OlaOla
    edited 2:28AM
    Thank you for the tip! We will try with the MemoryStream variant, it seems feasible for us.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.