C# .NET - Print Crystal report without viewing

Asked By Caleb 05 on 27-Jul-09 05:41 AM
Hi Frnd's....

Can anyone help me automatically print Crystal report without preview in c#.net windows application..

Tks in Adv...


Re - Ravenet Rasaiyah replied to Caleb 05 on 27-Jul-09 05:59 AM


Just use this sample code to do this


Thank you

re - Web Star replied to Caleb 05 on 27-Jul-09 06:02 AM

You can use

Report.PrintOut False 'printer report without prompt

and it would work :)

re - Web Star replied to Caleb 05 on 27-Jul-09 06:04 AM

You can print a Crystal Report using print option of Crystal Report Viewer. However, there are occasions when you want your application to print a report direct to printer without viewing the report in Crystal Report Viewer.


The ReportDocument class provides PrintToPrinter method that may be used to print a CR direct to the printer. If no printer is selected, the default printer will be used to send the printing pages to.


The PrintToPrinter method takes four parameters.


nCopies : Indicates the number of copies to print.

collated : Indicates whether to collate the pages.

startPageN : Indicates the first page to print.

endPageN : Indicates the last page to print.


The following steps will guide you to achieve the same:


  1. Add crystal report (.cr) file to your ASP.NET application.
  2. Add a report instance on the page level.

    Dim report As MyReport = New MyReport


  1. Populate reports data on Page_Init 

    ' Get data in a DataSet or DataTable

        Dim ds As DataSet = GetData()

        ' Fill report with the data



  1. Print Report
    report.PrintToPrinter(1, False, 0, 0)


If you wish to print certain page range, change last two parameters From to To page number.


If you want to set page margins, you need to create a PageMargin object and set PrintOptions of the ReportDocument.


The following code sets page margins and printer name:


Dim margins As PageMargins =  Report.PrintOptions.PageMargins

   margins.bottomMargin = 200

   margins.leftMargin = 200

   margins.rightMargin = 50

   margins.topMargin = 100



   ' Select the printer name

   Report.PrintOptions.PrinterName = printerName