Progress® Telerik® Reporting R2 2017

How do I display a PDF directly in the browser without exporting first?

To create a PDF and open it directly within a webform, use the ReportProcessor object to create a stream of bytes and write those bytes to the ASP.NET Response object. 

  1. Reference the reporting engine in your web application by adding reference to the Telerik.Reporting.dll assembly.
  2. Create ExportToPDF() method (see code example below) to your application.
  3. Call the ExportToPDF() method. For example you might call this within a button click event handler:
void ExportToPDF(string reportToExport)
{
    var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
    var typeReportSource = new Telerik.Reporting.TypeReportSource();

    // reportToExport is the Assembly Qualified Name of the report
    typeReportSource.TypeName = reportToExport;

    var result = reportProcessor.RenderReport("PDF", typeReportSource, null);

    this.Response.Clear();
    this.Response.ContentType = result.MimeType;
    this.Response.Cache.SetCacheability(HttpCacheability.Private);
    this.Response.Expires = -1;
    this.Response.Buffer = true;

    /* Uncomment to handle the file as attachment
     Response.AddHeader("Content-Disposition",
                    string.Format("{0};FileName=\"{1}\"",
                                    "attachment",
                                    fileName));
     */

    this.Response.BinaryWrite(result.DocumentBytes);
    this.Response.End();
}

See Also