Crystal Reports for Visual Studio .NET
ReportDocument.PrintToPrinter Method

Prints the specified pages of the report to the printer selected using the PrintOptions.PrinterName property. If no printer is selected, the default printer specified in the report will be used.

[Visual Basic]
Public Overridable Sub PrintToPrinter(ByVal nCopies AInteg, ByVal collated ABoole, ByVal startPageN AInteg, ByVal endPageN AInteg)
[C#]
public virtual void PrintToPrinteri nCopies bo collated i startPageN i endPageN );
[C++]
public virtual void PrintToPrinteri nCopies bo collated i startPageN i endPageN );
[VJ#]
public void PrintToPrinteri nCopies boole collated i startPageN i endPageN );

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.

Remarks

To print all pages, set the startPageN and endPageN parameters to zero.

Example

The following example sets the report's page margins, selects the printer, and prints the report.

[Visual Basic]
Private Sub PrintReport(ByVal printerName As String)
   Dim margins As PageMargins

   ' Get the PageMargins structure and set the 
   ' margins for the report.
   margins = Report.PrintOptions.PageMargins
   margins.bottomMargin = 350
   margins.leftMargin = 350
   margins.rightMargin = 350
   margins.topMargin = 350
   ' Apply the page margins.
   Report.PrintOptions.ApplyPageMargins(margins)

   ' Select the printer.
   Report.PrintOptions.PrinterName = printerName

   ' Print the report. Set the startPageN and endPageN
   ' parameters to 0 to print all pages.
   Report.PrintToPrinter(1, False, 0, 0)
End Sub 
[C#]
private void PrintReport(string printerName)
{
   PageMargins margins;

   // Get the PageMargins structure and set the 
   // margins for the report.
   margins = Report.PrintOptions.PageMargins;
   margins.bottomMargin = 350;
   margins.leftMargin = 350;
   margins.rightMargin = 350;
   margins.topMargin = 350;
   // Apply the page margins.
   Report.PrintOptions.ApplyPageMargins(margins);

   // Select the printer.
   Report.PrintOptions.PrinterName = printerName;

   // Print the report. Set the startPageN and endPageN
   // parameters to 0 to print all pages.
   Report.PrintToPrinter(1, false,0,0);
} 
[C++]
void PrintReport(String* printerName)
{
   PageMargins margins;

   // Get the PageMargins structure and set the 
   // margins for the report.
   margins = Report->PrintOptions->PageMargins;
   margins.bottomMargin = 350;
   margins.leftMargin = 350;
   margins.rightMargin = 350;
   margins.topMargin = 350;
   // Apply the page margins.
   Report->PrintOptions->ApplyPageMargins(margins);

   // Select the printer.
   Report->PrintOptions->PrinterName = printerName;

   // Print the report. Set the startPageN and endPageN
   // parameters to 0 to print all pages.
   Report->PrintToPrinter(1, false,0,0);
}; 
[VJ#]
private void PrintReport(String printerName)
{
   PageMargins margins;

   // Get the PageMargins structure and set the 
   // margins for the report.
   margins = Report.get_PrintOptions().get_PageMargins();
   margins.bottomMargin = 350;
   margins.leftMargin = 350;
   margins.rightMargin = 350;
   margins.topMargin = 350;
   // Apply the page margins.
   Report.get_PrintOptions().ApplyPageMargins(margins);

   // Select the printer.
   Report.get_PrintOptions().set_PrinterName(printerName);

   // Print the report. Set the startPageN and endPageN
   // parameters to 0 to print all pages.
   Report.PrintToPrinter(1, false,0,0);
} 

Requirements

Namespace: CrystalDecisions.CrystalReports.Engine

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP

See Also

ReportDocument Class | ReportDocument Members | CrystalDecisions.CrystalReports.Engine Namespace

Page view tracker