Merging reports into one

edited 7:56PM in FastReport .NET
Hi, i need in my mvc .net application to serve, after a user click, a SINGLE pdf file containing n reports merged together.
At the same time these reports must be saved ONE BY ONE in the server file system.
My idea was to the get the PreparedPages from all the single reports and put them in another report, this way:
                Report totalreport = new Report(); //merge of all reports
                totalreport.Prepare();

                foreach (ReportToCreate r in myreportsqueue)   //queue of objects containing reports to generate and their parameters
                {
                    Report report = new Report(); //a single report
                    report.SetParameterValue(r.ParName, r.ParValue);
                    report.Prepare(); 
                    PDFExport pdfex = new PDFExport();
                    report.Export(pdfex, fullFilePath); //computed path where to save the report

                    //add report pages to the total report
                    int pagine = report.PreparedPages.Count;
                    for (int nr=1; nr<=pagine; nr++)
                    {
                        var page = report.PreparedPages.GetPage(nr-1);
                        totalreport.PreparedPages.AddPage(page);
                    }
                }

                //send totalreport to browser
                MemoryStream stream = new MemoryStream();
                PDFExport pdf = new PDFExport();
                totalreport.Export(pdf, stream);

Unfortunately the last line of code gives the error: "Reference to an object not set to an instance...." with this stack trace:

in FastReport.Preview.PreparedPage.StartGetPage(Int32 index)
in FastReport.Export.ExportBase.ExportPageNew(Int32 pageNo)
in FastReport.Export.ExportBase.Export(Report report, Stream stream)


Any hint on how to achieve the result?
THX


Comments

  • edited May 2019
    Hi, try something like this:
    Report totalReport = new Report();
    totalReport.Load("pathToFirstReportTemplate");
    totalReport.SetParameterValue("totalReportParamName", "totalReportParamValue");
    totalReport.Prepare();
    
    foreach (ReportToCreate r in myReportsQueue)
    {
        totalReport.Load(r.pathToNextReportTemplate);
        totalReport.SetParameterValue(r.paramName, r.paramValue);
        totalReport.Prepare(true); // append report
    }
    
    MemoryStream memoryStream = new MemoryStream();
    PDFExport pdfExport = new PDFExport();
    totalReport.Export(pdfExport, memoryStream);
    

    You can use the same instance of the report (totalReport) and only append another reports.

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.