Skip to content

In this example, reports are printed in a single batch instead of sending one report at a time to the printer.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/reporting-winforms-print-reports-in-batch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reporting for WinForms - Print Multiple Reports in a Batch

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.

Print dialog

Implementation Details

  • 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.
// 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;
}

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

In this example, reports are printed in a single batch instead of sending one report at a time to the printer.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •