New to Telerik Reporting? Start a free 30-day trial
How do I display PDF directly in the browser without exporting first?
Environment
| Product | Progress® 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.
-
Reference the reporting engine in your web application by adding reference to the Telerik.Reporting.dll assembly.
-
Create ExportToPDF() method (see code example below) to your application.
-
Call the ExportToPDF() method. For example you might call this within a button click event handler:
CSharpvoid 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(); }