Tuesday, December 16, 2008

Printing Crystal Report

Printing crystal report is sometimes very tedious task according to user requirement. Because most of the time users do not need to view the report and they just want to print it. There are three methods available for crystal report to print the report.
1. Using ActiveX method
2. Using Adobe method
3. Using direct export

But there is a way to print the report directly from printer (should install in web server) but it is not practicable for large company.

Above ActiveX is better but it has some security problem (want high authority to use ActiveX) and also it need the Internet connection to connect to report vendor to get print control only at first loading. And also this type has some undiscovered problems like print control loading and suddenly disappearing problem, etc.
Second method provide some flexibility and it do not need high authority but the main drawback is user have to pass several steps to complete the printing process.
Third way provide user to export the document to various formats and it also give the facility to directly load the exported document to browser (using code)if user machine installed the exported document application. The most convenient way is to export it into adobe format because adobe reader freely available. And this removes unnecessary steps to print the adobe document in second way of printing. You want to add small coding part.

For C# User
Normally you end up with setting report viewer source as report document. You can comment that line and enter following code

MemoryStream oStream = new MemoryStream();
oStream = (MemoryStream)rd.ExportToStream(ExportFormatType.PortableDocFormat);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(oStream.ToArray());
Response.End();


You want to know ‘MemoryStream’ is in ‘System.IO’