New to Telerik Reporting? Download free 30-day trial

Modifying Report Document Before Serving It To the Viewer

Environment

Product Progress® 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:

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 
    }
}
Public Sub New()
    InitializeComponent()
    AddHandler Me.reportViewer1.ExportEnd, AddressOf ReportViewer1ExportEnd
End Sub

Private Sub ReportViewer1ExportEnd(sender As Object, args As Telerik.ReportViewer.Common.ExportEndEventArgs)
    If args.DocumentExtension.Equals("pdf") Then
        'modify the rendered document in args.DocumentBytes
    End If
End Sub

Web Viewers

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

Web API

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 
        }
    }
}
Public Class ReportController Inherits Telerik.Reporting.Services.WebApi.ReportsControllerBase
    Protected Overrides Sub OnGetDocument(args As Telerik.Reporting.Services.GetDocumentEventArgs)
        If args.Extension = "PDF" Then
            'modify the rendered document in args.DocumentBytes
        End If
    End Sub
End Class

ServiceStack

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 
        }
    }
}
Public Class ReportController Inherits Telerik.Reporting.Services.WebApi.ReportsControllerBase
    Protected Overrides Sub OnGetDocument(args As Telerik.Reporting.Services.GetDocumentEventArgs)
        If args.Extension = "PDF" Then
            'modify the rendered document in args.DocumentBytes
        End If
    End Sub
End Class
In this article