How to print crystal report without Report Viewer or any print dialog in C#

The following example demonstrates how we can print Crystal report without using report viewer or any print preview dialog. From below code we can print crystal report to Printer directly:

Example

private void PrintToPrinter()
        {
            PrintReport(System.Windows.Forms.Application.StartupPath + "\\CrystalReport1.rpt", 
                "Send To OneNote 2010");
        }
private void PrintReport(string reportPath, string PrinterName)
        {
            CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc = 
                                new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            rptDoc.Load(reportPath);
 
            CrystalDecisions.Shared.PageMargins objPageMargins;
            objPageMargins = rptDoc.PrintOptions.PageMargins;
            objPageMargins.bottomMargin = 100;
            objPageMargins.leftMargin = 100;
            objPageMargins.rightMargin = 100;
            objPageMargins.topMargin = 100;
            rptDoc.PrintOptions.ApplyPageMargins(objPageMargins);
            rptDoc.PrintOptions.PrinterName = PrinterName;
            rptDoc.PrintToPrinter(1, false, 0, 0);
        }

rptDoc.PrintToPrinter method prints the specified pages of the report to the printer selected with the help of the PrintOptions.PrinterName property. If no printer is selected, the default printer specified in the report will be used.

We are using PrintToPrinter method as :

public void PrintToPrinter (int nCopies , boolean collated , int startPage , int endPage );

where
nCopies indicates the number of copies to print.
collated indicates whether to collate the pages.
startPage indicates the first page to print.
endPage indicates the last page to print.

from the above we are calling this method as rptDoc.PrintToPrinter(1, false, 0, 0);, means we are printing one copy, and all pages. To print all pages, we set the startPage and endPage parameters to zero.