New to Telerik Reporting? Download free 30-day trial

Print a Report Programmatically

Environment

Product Progress® Telerik® Reporting
Report Viewer All

Description

The ability to print a report is widely used feature that a Reporting product cannot go without. The ReportViewers we provide for viewing the reports, come with a Print button that takes care of this automatically. However, in case one might want to be in control over the printing - use the exposed methods.

Solution

HTML5 Report Viewers

For the HTML5-based report viewers, you could use the print command. For example:

$('#printButton').click(function () {
    var rv = $("#reportViewer1").data("telerik_ReportViewer");
    rv.commands.print.exec();
});

The example above selects an HTML element with the printButton id using jQuery and in the click event handler invokes report viewer print command. Note that the exec() method of the command needs to be called.

Desktop Report Viewers (WinForms/WPF)

Both Report Viewers come up with out-of-the-box methods for printing the report through code.

Alternatively, the ReportProcessor.PrintReport() method could also be used. It accepts two parameters  - a ReportSource and the PrinterSettings that should be used.

For example, here is how to print the Barcodes Report from the ReportLibrary class library project that can be found in the installation folder of the product - {installation folder}\Examples\CSharp\.NET Framework\ReportLibrary.

ReportProcessor reportProcessor = new ReportProcessor();
reportProcessor.PrintReport(new TypeReportSource() { TypeName = typeof(BarcodesReport).AssemblyQualifiedName }, new PrinterSettings());

Legacy ASP.NET WebForms Report Viewer

To print a report through the Legacy ASP.NET ReportViewer, you need to use the built-in print functionality. It depends on the Adobe Acrobat Reader PDF plugin (you need it installed to take advantage of true print and not the browsers' printing capabilities) and you have the option to select a printer from a list.

On the client side, you can invoke the print through the ReportViewer client object's PrintReport() method:

<form id="form1" runat="server">
    <telerik:ReportViewer runat="server" id="ReportViewer1"></telerik:ReportViewer>
    <script type="text/javascript">
        <%=ReportViewer1.ClientID %>.PrintReport();
    </script>
</form> 

See Also

In this article