Programmatically output a Report Book to PDF

2 posts, 0 answers
  1. steven schmalfeld
    steven schmalfeld avatar
    9 posts
    Member since:
    Dec 2006

    Posted 23 Mar Link to this post

    I have seen the article on how to export to pdf without going through the viewer, but it does not seem to aply to a report book (it may just be me :))

    Could I have an example where several reports are added to a report book and then the report book is sent directly to PDF?
  2. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 25 Mar Link to this post

    Hello Steven,

    The ReportBook object is the same as the Report object. The ReportBook is treated as a single document on display, export, print.

    Please check the ReportBook example in the local demos installed by default under C:\Program Files (x86)\Telerik\Reporting Q1 2016\Examples.
    If you want to create the ReportBook at run-time and export it programmatically, test the following approach:
    ReportBook reportBook = new ReportBook();
    reportBook.Reports.Add(new TableOfContentsReport());
    switch (DateTime.Now.DayOfWeek)
    {
       case DayOfWeek.Saturday:
       case DayOfWeek.Sunday:
            reportBook.Reports.Add(new WeekendReport());
            break;
       default:
            reportBook.Reports.Add(new WeekdayReport());
            break;
    }
    reportBook.Reports.Add(new GlossaryReport());
    reportBook.Reports.Add(new IndexReport());
     
    Telerik.Reporting.Processing.ReportProcessor reportProcessor =
        new Telerik.Reporting.Processing.ReportProcessor();
     
    // set any deviceInfo settings if necessary
    System.Collections.Hashtable deviceInfo =
        new System.Collections.Hashtable();
     
    //wrap the document in a report source
     var IRS =  new Telerik.Reporting.InstanceReportSource();
     IRS.ReportDocument = reportBook;
     
    Telerik.Reporting.Processing.RenderingResult result =
        reportProcessor.RenderReport("PDF", IRS, deviceInfo);
     
    string fileName = result.DocumentName + "." + result.Extension;
    string path = System.IO.Path.GetTempPath();
    string filePath = System.IO.Path.Combine(path, fileName);
     
    using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
    {
        fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
    }


    Let us know if you have any further questions.

    Regards,
    Stef
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
Back to Top