• Javascript
  • Python
  • Go

Print Button for SSRS in Chrome and Firefox

The ability to print reports is an essential feature in any reporting tool. However, users of SQL Server Reporting Services (SSRS) have face...

The ability to print reports is an essential feature in any reporting tool. However, users of SQL Server Reporting Services (SSRS) have faced challenges when it comes to printing in Chrome and Firefox browsers. In this article, we will explore how to add a print button for SSRS reports in these two browsers.

Before we dive into the details, let's understand the root cause of the issue. The problem lies in the fact that Chrome and Firefox do not support ActiveX controls, which are essential for printing in SSRS. As a result, when users try to print a report in these browsers, they are met with error messages or blank pages.

To overcome this limitation, we need to find an alternative solution for printing in SSRS. One way to achieve this is by using JavaScript. By adding a print button to the report that triggers a JavaScript function, we can bypass the need for ActiveX controls.

To begin, let's create a new report in SSRS or open an existing one. Then, go to the report properties and add a new parameter called "PrintButton" with a default value of "False." This parameter will serve as a trigger for our JavaScript function.

Next, we need to add a text box to the report and place it in the report header or footer. This text box will act as our print button. Right-click on the text box and select "Textbox Properties." In the Action tab, select "Go to URL" and click on the "fx" button to enter an expression. In the expression, we will use the JavaScript function "window.print()" to trigger the print dialog box. The complete expression will look like this:

=IIF(Parameters!PrintButton.Value="True","javascript:void(window.print())","")

Now, when the report is rendered, the text box will only be visible if the PrintButton parameter is set to "True." This will ensure that the print button is only available when the report is viewed in Chrome or Firefox.

However, there is one more step we need to take to make this work in Chrome and Firefox. We need to make sure that the "PrintButton" parameter is set to "True" when the report is viewed in these browsers. To do this, we will use the User Agent property in SSRS.

Go to the report properties and select the Code tab. Here, we will add the following code:

Public Function GetUserAgent() As String

Return System.Web.HttpContext.Current.Request.UserAgent

End Function

Now, go back to the report properties and add an expression to the PrintButton parameter, as shown below:

=IIF(Code.GetUserAgent().Contains("Chrome") OR Code.GetUserAgent().Contains("Firefox"),"True","False")

This expression will check the User Agent string and set the PrintButton parameter to "True" if the report is viewed in Chrome or Firefox. And that's it! We have successfully added a print button for SSRS reports in Chrome and Firefox.

In conclusion, by using JavaScript and the User Agent property in SSRS, we can overcome the limitations of ActiveX controls and provide a seamless printing experience for our users in Chrome and Firefox. With this solution, users can now print their reports without any errors or blank pages. So, go ahead and add this feature to your SSRS reports and make printing hassle-free for your users.

Related Articles

jQuery: Optimal DOM Insertion Speed

jQuery is a popular JavaScript library that is widely used for its ease of use and powerful features. One of its key features is DOM manipul...

jQuery: How to append $(this)

jQuery: How to append $(this) In the world of web development, jQuery has become a popular and powerful tool for creating dynamic and intera...