Appending Multiple Reports into Single PDF

Posted by: shailendramalik on 27 September 2017, 6:49 pm EST

  • Posted 27 September 2017, 6:49 pm EST

    I have to provide a functionality to show multiple reports in one PDF. We are generating individual reports using RenderToStream() provided by class C1.C1Report.C1Report which returns pdf Stream. Combining those individual report streams isn’t working to show all reports into single PDF. It only shows the last PDF, perhaps the last PDF marks it’s starting and ending offsets in stream (making the previously added PDFs unrecognizable for the browser showing those PDF reports). Do C1 classes provide something to achieve this functionality?

    Can you please share some sample code to achieve this.

    Thanks

  • Posted 27 September 2017, 6:49 pm EST

    You can render your reports (via C1Report.Render()), put all page metafiles (accessed via C1Report.C1Document.Pages) into a single list, and feed it to PDF exporter. Unlike most other exporters, PDF is exported via metafiles anyway so this will not result in any loss of quality. Here's some sample code to get you started:

    C1Report rep1 = new C1Report();

    rep1.Load(@"CommonTasks.xml", "01: Alternating Background (Greenbar report)");

    C1Report rep2 = new C1Report();

    rep2.Load(@"CommonTasks.xml", "02: Custom Paper Size");

    rep1.Render();

    rep2.Render();

    List merged = new List();

    foreach (C1Page pg in rep1.C1Document.Pages)

    merged.Add(pg.AsMetafile());

    foreach (C1Page pg in rep2.C1Document.Pages)

    merged.Add(pg.AsMetafile());

    C1.C1Preview.Export.PdfExporter exporter =

    C1.C1Preview.Export.ExportProviders.PdfExportProvider.NewExporter()

    as C1.C1Preview.Export.PdfExporter;

    exporter.Document = merged;

    // adjust export options as needed, e.g.:

    exporter.ShowOptions = false;

    exporter.Export(@"myfile.pdf");

    Hope this helps.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels