This documentation is archived and is not being maintained.

ReportDocument.PrintToPrinter Method

Visual Studio .NET 2003

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 As Integer, ByVal collated As Boolean, ByVal startPageN As Integer, ByVal endPageN As Integer)
[C#]
public virtual void PrintToPrinter (int nCopies , bool collated , int startPageN , int endPageN );
[C++]
public virtual void PrintToPrinter (int nCopies , bool collated , int startPageN , int endPageN );
[VJ#]
public void PrintToPrinter (int nCopies , boolean collated , int startPageN , int 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

Show: