Printing
You can print a report two ways with Crystal Reports for Visual Studio:
- From the GUI, with the Print button on the toolbar that is provided with the CrystalReportViewer control on a Web or Windows Form.
- From the SDK, with the ReportDocument object.
Printing from the GUI
In a Windows application, the print button on the CrystalReportViewer control toolbar opens the standard print dialog box.
In a Web application the print button on the CrystalReportViewer control toolbar opens a secondary Web page that emulates a print dialog box. A pdf is generated on the Web server, and then downloaded and displayed on the Web page. (It works much like Print Preview.)
Printing from the SDK
Users typically print reports from their own machines, with the print button in the toolbar of the CrystalReportViewer control. However, if you design a Web application in which reports are printed on the Web server, you could write code with the ReportDocument object model to print reports directly from the server to a specific printer.
Printing using the ActiveX control
In recent versions of Crystal Reports, you can specify the print mode using the new CrystalReportViewer.PrintMode property. It contains two enumerated types: ActiveX, and PDF.
- When the property is set to PrintMode.PDF, the report is exported as a PDF on the Web server, and then streamed to the browser. The user is given the option to print directly to the printer. This option is cross-platform compatible.
- When the property is set to PrintMode.ActiveX, an ActiveX
printing control allows users to print the report directly to their
local printer.
Note
In Crystal Reports for Visual Studio 2005 and later, the ActiveX print control is not installed on the local machine. Instead, it must be accessed as a .cab file from an external URL. The PrintControl.cab file can be downloaded from the Business Objects tech support Web Site, at which point you can place the cab file in a web server virtual directory for URL access. To make the cab file visible to your Crystal Reports for Visual Studio Web Site, add the following xml to your Web Site's web.config file:
<configSections> <sectionGroup name="businessObjects"> <sectionGroup name="crystalReports"> <section name="printControl" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null" /> </sectionGroup> </sectionGroup> </configSections> <businessObjects> <crystalReports> <printControl> <add key="url" value="http://myserver/PrintControl.cab" /> </printControl> </crystalReports> </businessObjects>
Note
Only Internet Explorer supports ActiveX controls. Printing from a non-Internet Explorer client (FireFox, Safari, Mozilla, and others) reverts to the PDF export dialog.