Save yourself the trouble of having to reload printer trays in the middle of printing — or from wasting special types of paper — by printing an ActiveReports report from multiple printer trays.

In this blog post, we'll go over how to print from multiple trays using an example that's based on a support question we received.

The Scenario

Our customer has a section report that was set up to print 35 records per page on pre-printed check forms. They want to add between 1 and 999 records to their report, but they want to avoid wasting pre-printed check forms. Their printer has two trays: the first tray contains the pre-printed check forms, and the second contains plain A4 paper.

To save the pre-printed check forms, the customer wants to print their report so that they only use one page of the pre-printed check forms. Depending on how many records they add to the report, they would need to print in one of the following ways:

  • If there are 35 records or less, they can simply print the report on a single page from Tray 1 (the pre-printed check forms).
  • If there are more than 35 records, they need to print the first page (35 records) of the report from Tray 1, and then print the remaining records from Tray 2 on plain paper.

Let's say the customer adds 58 records to their report: they'll need to print 23 records (a second page) from the second tray after printing the first 35 records from the first tray.

Printing from Multiple Trays

To print the first page from Tray 1 and the second page from Tray 2, the customer needs to handle the PrintProgress event of the SectionDocument class, and use logic to change the PaperSource property if the CurrentPage property is greater than one.

The customer would use the following code to print their first page and subsequent pages from different printer trays with C# code:

private void button1_Click(object sender, EventArgs e)
{
  try
  {
    //Handle the PrintProgress event for the report.
    rpt.Document.PrintProgress += Document_PrintProgress;
    // Print the report after running the code in the PrintProgress event.
    rpt.Document.Print(false);
  }
  catch (Exception ex)
  {

  }
}

// Create the PrintProgress event.
private void Document_PrintProgress(object sender,
 GrapeCity.ActiveReports.Extensibility.Printing.PrintProgressEventArgs e)
{
  var doc = sender as SectionDocument;

  // Set the paper tray to use for pages other than the first one.
  if (e.CurrentPage > 1)
   {
     doc.Printer.DefaultPageSettings.PaperSource =
      doc.Printer.PrinterSettings.PaperSources[2];
   }
   // Set the paper tray to use for the first page.
   else
   {
     doc.Printer.DefaultPageSettings.PaperSource =
      doc.Print.PrinterSettings.PaperSources[0];
   }
}

If the customer wanted to use VB code to set up printing from multiple trays, they would follow this code:

Private Sub Button1_Click(sender As Oject, e As EventArgs)
  Try
    'Handle the PrintProgress event for the report.
    AddHandler rpt.Document.PrintProgress, _
     AddressOf Document_PrintProgress
    'Print the report after running the code in the PrintProgress event.
    rpt.Document.Print(False)

  Catch ex As Exception
  End Try
End Sub

'Create the PrintProgress event.
Private Sub Document_PrintProgress(sender As Object, e As _
 GrapeCity.ActiveReports.Extensibility.Printing.PrintProgressEventArgs)
  Dim doc = TryCast(sender, SectionDocument)

  'Set the paper tray to use for pages other than the first one.
  If e.CurrentPage > 1 Then
     doc.Printer.DefaultPageSettings.PaperSource = _
      doc.Printer.PrinterSettings.PaperSources(2)
  'Set the paper tray to use for the first page.
  Else
    doc.Printer.DefaultPageSettings.PaperSource = _
     doc.Printer.PrinterSettings.PaperSources(0)
  End If
End Sub

The customer's report should print from both printer trays. Even though we followed an example to demonstrate how to print from multiple trays, you can modify the above code for your own multi-tray printing needs.

Download your free 30-day trial of ActiveReports today.