Merge prepared reports

Hi,

I need to merge several reports together and export the result to pdf. I've seen in the FAQ the following snippet:

Report report = new Report(); 
report.Load(Path.GetFullPath(@"..\..\Report1.frx")); 
report.Prepare(true); 
report.Load(Path.GetFullPath(@"..\..\Report2.frx")); 
report.Prepare(true); 
report.Load(Path.GetFullPath(@"..\..\Report3.frx")); 
report.Prepare(true); 
report.ShowPrepared();

But doing this messes the "PrintOn" property in my reports. In the example above, if I configure something in Report2.frx with property "PrintOn" set as "SinglePage", it never will be printed as the result report has already the page(s) from Report1.frx...

What would be the correct way to achieve this task? I've tried to export each report individually to pdf and merge the streams, but I see only the first report when I open the pdf.

Thanks in advance for any advice

Comments

  • Hello!

    Calling `report.Load(...)` and `report.Prepare(true)` in turn on a single instance of `Report` only works correctly if the previous data or prepared pages are not overwritten by the new connection. The cleanest and safest way to combine different reports into a single PDF is as follows:

    using var report = new Report();
    string[] files = { @‘..\..\Report1.frx’, @‘..\..\Report2.frx’, @‘..\..\Report3.frx’ };
    for (int i = 0; i < files.Length; i++)
    {
    report.Load(Path.GetFullPath(files[i]));
    // If necessary, register the data specifically for this report:
    // report.RegisterData(...);
    report.Prepare(append: i > 0);
    }
    using var pdf = new FastReport.Export.Pdf.PDFExport();
    report.Export(pdf, ‘merged.pdf’);
    

    Please note: for the first report, pass `append: false` (or call `report.Prepare()` without any parameters), and only for the second and subsequent reports, use `report.Prepare(true)` (`append: true`).

This discussion has been closed.