Client Printing Support in SQL Server Reporting Using SOAP
 
Published: 26 Jun 2007
Abstract
The article is about printing reports directly from an application using the rendering of the reports with the help of web services exposed by Microsoft to access Report Server.
by vikas chaudhary
Feedback
Average Rating: 
Views (Total / Last 10 Days): 19708/ 55

Introduction

As the reports rendered by the "Render()" web method do not support the toolbar provided in the "ReportViewer" control, it makes a difficult choice for a programmer to print reports from the application directly.

One of the method to use, the printing functionality as in toolbar of the ReportViewer control, can be implemented by certain customization in the application. This can be said as Direct Client printing Technique obtained by the combination of certain HTML and JavaScript Code.

The procedure starts by adding a simple object in your HTML at the page as shown

Firstly, add a tag named object to the HTML file under the <body> tag.

Listing 1

<OBJECT id="RSClientPrint" codeBase=
"http://urservername/reportserver?rs:Command=Get&
rc:GetImage=9.00.3042.05rsclientprint.cab#Version=2005,090,3042,000"
 classid="CLSID:FA91DF8D-53AB-455D-AB20-F2F023E498D3" VIEWASTEXT> </OBJECT>

Then write a function; in our example it is named PrintAll(), which sets the properties of the page to be printed using this object "RSClientPrint."

You can call this function on any event at <body onload =PrintAll()>.

Listing 2

function PrintAll() 
{ 
RSClientPrint.MarginLeft = 12.7; 
RSClientPrint.MarginTop = 12.7; 
RSClientPrint.MarginRight = 12.7;
 RSClientPrint.MarginBottom = 12.7; 
RSClientPrint.Culture = 1033;
 RSClientPrint.UICulture = 9; 
RSClientPrint.Print('http://<ur server name>/ReportServer',
  '/Report Project/report1&Param1=in&Param2=497&Param3=1', 'report1') 
}

This code works as in ReportViewer toolbar print button uses the ActiveX control i.e. RSClientPrint Class, to open a print dialog box which enables the client computer to customize the print settings and enables easy client printing.

Besides this, a lot more is there if you dig in details of the functionality behind this, but that requires thorough reporting knowledge and some hands on experience in windows API dealing with System32.dll. You should learn about extracting the basic functionality of the printing that is avoided, so as not to create confusion as well as using the code straight forwardly in the application.

Tackling Errors

One may get some problems implementing this. The most common are listed below.

You may get an error as "Error loading resource library. (0x80004002)."

For this you need to install the ActiveX control explicitly once before using the object. To resolve this you need to run the report from report manager and install the ActiveX provided from the toolbar of the Report Server. Additionally your client browser should allow ActiveX to permit download.

Another problem that can occur during execution is an unhandled exception of type "System.InvalidCastException" occurred in CoMALite.exe.

To resolve this you need to check your version of the downloaded control that can be done by checking the downloaded control itself. For that, go to path C: or your windows drive and check %windir% folder generally C:\windows. Then in "\Downloaded Program Files," you will see RSClientPrint Class as a downloaded ActiveX and it will be shown along with status(installed), size, date and version. If the problem persists, try deleting this and again installing the control.

This makes the client printing easy and almost effortless if the application uses the web method for rendering reports and without using the ReportViewer control that is extensively used in Visual Studio 2005.

Conclusion

In this article we have seen how to print the reports directly from the application using the rendering of reports with help of web services exposed by Microsoft to access Report Server. It also briefly discussed how to fix certain errors which you might encounter while implementing the functionality.

Happy Programming!



User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-12-08 8:22:13 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search