New to Telerik ReportingStart a free 30-day trial

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

Environment

ProductProgress® Telerik® Reporting

Description

Do you want to create a PDF and open it directly within a webform?

Solution

Use the ReportProcessor.RenderReport method 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:

    CSharp
    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();
    }
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support