Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

14.04 Printing to the Printer

Sending Reports Directly to the Printer

If you want to send the report directly to the printer without previewing it, call the PrintToPrinter() methodWhen you call this method, the report is sent directly to the printer without any user interaction. This is useful when generating reports in a batch format or if you are creating a custom toolbar with a print button on it. The parameters of the PrintToPrinter() method are listed in Table 14-1.

Table 14-1. PrintToPrinter() parameters.

Parameter Description
nCopie The number of copies to print.
Collate Set to True to collate the pages.
startPage The first page to print. Set to 0 to print all pages.
endPage The last page to print. Set to 0 to print all pages.

All the parameters listed in Table 14-1 are required. If you don’t need to use one or more of them, pass it the default value.The first parameter, nCopies, sets how many copies of the report to print. If more than one copy of the report is being printed, the second property tells whether or not to collate the copies. Passing False tells it to print each full report prior to printing the next copy. The collated property is only used if nCopies is greater than 1. Otherwise it is ignored. The last two parameters, startPageN and endPageN, set the page range. Pass it the first page to print and the last page to print. To print the entire report, pass 0 to both parameters.

Listing 14-4. Windows client, non-embedded report, print to printer
[VB.NET]
Dim myReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
myReport.Load("CrystalReport1.rpt")
myReport.PrintToPrinter(1, False, 0, 0)
[C#]
CrystalDecisions.CrystalReports.Engine.ReportDocument() myReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
myReport.Load("CrystalReport1.rpt");
myReport;.PrintToPrinter(2, True, 0, 0);

This code is similar to the previous listings with the exception that the report is sent directly to the printer. The VB.NET example prints one copy of the entire report. The C# example prints 2 copies and collates the report pages.