Back to Devexpress

Print Multiple Reports in a Batch

xtrareports-400037-desktop-reporting-common-features-printing-winforms-reporting-print-api-print-multiple-reports-in-a-batch.md

latest5.0 KB
Original Source

Print Multiple Reports in a Batch

  • Sep 03, 2025
  • 3 minutes to read

This example sends multiple reports to the printer. The Print dialog appears only once before the first report is printed. This dialog specifies print settings for all reports.

View Example: Print Multiple Reports in a Batch

  • Use the PrintTool.PrintDialog method for the first report to display the Print dialog and specify print settings.

  • Handle the StartPrint event to capture these settings and apply them to each report before printing.

  • Call the Print method to print subsequent reports with the same printer settings, without prompting the user again.

  • C#

  • VB.NET

csharp
using System.Drawing.Printing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;

// Stores the printer settings selected by the user in the print dialog.
private PrinterSettings prnSettings;

// Handles the button click event to start the batch printing process.
private void button1_Click(object sender, EventArgs e) {
    XtraReport1 report1 = new XtraReport1();
    XtraReport[] reports = new XtraReport[] { new XtraReport2(), new XtraReport3() };

    // Creates a print tool for the first report and subscribe to the StartPrint event.
    ReportPrintTool pt1 = new ReportPrintTool(report1);
    pt1.PrintingSystem.StartPrint += new PrintDocumentEventHandler(PrintingSystem_StartPrint);

    // Subscribes to the StartPrint event for each additional report.
    foreach (XtraReport report in reports) {
        ReportPrintTool pts = new ReportPrintTool(report);
        pts.PrintingSystem.StartPrint += new PrintDocumentEventHandler(reportsStartPrintEventHandler);
    }

    // Shows the print dialog for the first report.
    if(pt1.PrintDialog() == true) {
        // If the user confirms, print all additional reports with the selected printer settings
        foreach(XtraReport report in reports) {
            ReportPrintTool pts = new ReportPrintTool(report);
            pts.Print();
        }
    }
}

// Event handler to capture the printer settings from the print dialog.
void PrintingSystem_StartPrint(object sender, PrintDocumentEventArgs e) {
    prnSettings = e.PrintDocument.PrinterSettings;
}

// Event handler to apply the captured printer settings to each report before printing.
private void reportsStartPrintEventHandler(object sender, PrintDocumentEventArgs e) {
   int pageCount = e.PrintDocument.PrinterSettings.ToPage;
   e.PrintDocument.PrinterSettings = prnSettings;

   // Ensures all pages are printed, even if reports have different page counts.
   e.PrintDocument.PrinterSettings.ToPage = pageCount;
}
vb
Imports System.Drawing.Printing
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI

' Stores the printer settings selected by the user in the print dialog.
Private prnSettings As PrinterSettings

' Handles the button click event to start the batch printing process.
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim report1 As New XtraReport1()
    Dim reports() As XtraReport = {
        New XtraReport2(),
        New XtraReport3()
    }

    ' Creates a print tool for the first report and subscribe to the StartPrint event.
    Dim pt1 As New ReportPrintTool(report1)
    AddHandler pt1.PrintingSystem.StartPrint, AddressOf PrintingSystem_StartPrint

    ' Subscribes to the StartPrint event for each additional report.
    For Each report As XtraReport In reports
        Dim pts As New ReportPrintTool(report)
        AddHandler pts.PrintingSystem.StartPrint, AddressOf reportsStartPrintEventHandler
    Next report

    ' Shows the print dialog for the first report.
    If pt1.PrintDialog() = True Then
        ' If the user confirms, print all additional reports with the selected printer settings
        For Each report As XtraReport In reports
            Dim pts As New ReportPrintTool(report)
            pts.Print()
        Next report
    End If
End Sub

' Event handler to capture the printer settings from the print dialog.
Private Sub PrintingSystem_StartPrint(ByVal sender As Object, ByVal e As PrintDocumentEventArgs)
    prnSettings = e.PrintDocument.PrinterSettings
End Sub

' Event handler to apply the captured printer settings to each report before printing.
Private Sub reportsStartPrintEventHandler(ByVal sender As Object, ByVal e As PrintDocumentEventArgs)
   Dim pageCount As Integer = e.PrintDocument.PrinterSettings.ToPage
   e.PrintDocument.PrinterSettings = prnSettings

   ' Ensures all pages are printed, even if reports have different page counts.
   e.PrintDocument.PrinterSettings.ToPage = pageCount
End Sub

See Also

Merge Reports