New to Telerik ReportingStart a free 30-day trial

Modifying Report Document Before Serving It To the Viewer

Environment

ProductProgress® Telerik® Reporting

Description

With Telerik Reporting R3 2016 we introduced a point granting you access to rendered reports before providing them to the client.

In the following code snippets we demonstrate how to modify a report rendered in PDF format from desktop report viewers or service prior serving the report to the viewer client. The code snippets cover both desktop viewers and web viewers.

Solution

Desktop Viewers

Open the Windows Form or WPF Window code behind (press F7) and handle report viewer event ExportEnd as shown in the following snippet:

C#
public ReportViewerFormOrWindow()
{
	InitializeComponent();
	this.reportViewer1.ExportEnd += ReportViewer1ExportEnd;
}

private void ReportViewer1ExportEnd(object sender, Telerik.ReportViewer.Common.ExportEndEventArgs args)
{
	if(args.DocumentExtension.Equals("pdf"))
	{
		//modify the rendered document in args.DocumentBytes 
	}
}

Web Viewers

In case you use Web viewer you have to overide the Telerik Reporting service method OnGetDocument:

Web API

C#
public class ReportController : Telerik.Reporting.Services.WebApi.ReportsControllerBase
{
	protected override void OnGetDocument(Telerik.Reporting.Services.GetDocumentEventArgs args)
	{
		if(args.Extension.Equals("pdf"))
		{
			//modify the rendered document in args.DocumentBytes 
		}
	}
}

ServiceStack

C#
public class ReportController : Telerik.Reporting.Services.WebApi.ReportsControllerBase
{
	protected override void OnGetDocument(Telerik.Reporting.Services.GetDocumentEventArgs args)
	{
		if(args.Extension.Equals("pdf"))
		{
			//modify the rendered document in args.DocumentBytes 
		}
	}
}