This is a migrated thread and some comments may be shown as answers.

Programmatically output a Report Book to PDF

1 Answer 967 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
steven schmalfeld
Top achievements
Rank 2
steven schmalfeld asked on 23 Mar 2016, 10:05 PM
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?

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 25 Mar 2016, 12:56 PM
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
Ajay
Top achievements
Rank 1
commented on 15 Nov 2023, 12:08 PM

Thank you this was helpful I am able to fix the issue, but one issue I am observing;

Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer can't Deserialize Trbp files. 

I had to manually open trbp files and read definition xml file to extract trdp files and add it to reportbook.

Then I am able to export PDF in the backend.

 

 //    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
 //    reportBook = (Telerik.Reporting.ReportBook)xmlSerializer.Deserialize(streambook);
 //}
 //foreach (var item in reportBook.Reports)
 //{
 //    MemoryStream ms1 = new MemoryStream();
 //    using (FileStream file = System.IO.File.OpenRead(item.Report.DocumentName))
 //    {
 //        file.CopyTo(ms1);
 //    }

 //}

 

using (var zip = new ZipArchive(streambook, ZipArchiveMode.Read))
{
    var entr = zip.Entries.Where(x => x.Name.StartsWith("definition")).FirstOrDefault();
    var audit = zip.GetEntry("definition.xml");
    StreamReader reader = new StreamReader(entr.Open());
    string text = reader.ReadToEnd();
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(text);

 

.......

 

Dimitar
Telerik team
commented on 20 Nov 2023, 09:06 AM

Hello Ajay,

The Report Book (.trbp) extension is an archive so in order to create a Telerik.Reporting.ReportBook object, you may use the ReportPackager class.

Please see the examples in the Packaging Report Definitions Explained - Telerik Reporting article for more details.

Tags
General Discussions
Asked by
steven schmalfeld
Top achievements
Rank 2
Answers by
Stef
Telerik team
Share this question
or