Home / Community & Support / Knowledge Base / Telerik Reporting / Designing Reports / Saving a report into PDF format programmatically

Saving a report into PDF format programmatically

Article Info

Rating: 5

Article information

Article relates to

Telerik Reporting 

Created by

Trayko, Telerik

Last modified

June 29, 2009

Last modified by

Steve, Telerik



HOW-TO
Save a report into PDF format programmatically

SOLUTION
To save a report in PDF you have to use FileStream and write the bytes of the rendered report in it. Here is an example: 

C#

void SaveReport(Telerik.Reporting.Report report, string fileName) 
    { 
        ReportProcessor reportProcessor = new ReportProcessor(); 
        RenderingResult result = reportProcessor.RenderReport("PDF", report, null); 
 
        using (FileStream fs = new FileStream(fileName, FileMode.Create)) 
        { 
            fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length); 
        } 
    }     

VB.NET

Sub SaveReport(report As Telerik.Reporting.Report, fileName As String
    Dim reportProcessor As New ReportProcessor() 
    Dim result As RenderingResult = reportProcessor.RenderReport("PDF", report, Nothing
 
    Using fs As New FileStream(fileName, FileMode.Create) 
        fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length) 
    End Using 
End Sub 

The function is called in the following way:

    SaveReport(new MyReport(), @"C:\MyReport.pdf");

Comments

  • Jose Ferreira Lima Filho , Jun 30, 2008

    very good article

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.