Skip to main content

Share Printer Settings Between Reports

  • 2 minutes to read

This example demonstrates how to use the same printer settings for multiple reports. It invokes the Print dialog for the first printed report only, and then prints all other reports using the specified printing settings.

Handle the PrintingSystemBase.StartPrint event for all the target reports and use the event argument’s PrintDocument property to access the PrinterSettings property.

Call the PrintHelper.PrintDirect method for the first report to open the Print dialog and the PrintHelper.PrintDirect method for the other reports.

using System.Drawing.Printing;
using DevExpress.Xpf.Printing;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting;
//... 

private PrinterSettings printingSettings;

private void simpleButton_Click(object sender, RoutedEventArgs e) {
    XtraReport1 report1 = new XtraReport1();
    XtraReport[] reports = new XtraReport[] { new XtraReport2(), new XtraReport3() };

    report1.PrintingSystem.StartPrint += new PrintDocumentEventHandler(FirstReportEventHandler);

    foreach (XtraReport report in reports) {
        report.PrintingSystem.StartPrint += new PrintDocumentEventHandler(OtherReportsEventHandler);
    }

    PrintHelper.Print(report1); 
    foreach (XtraReport report in reports) {
        PrintHelper.PrintDirect(report); 
    }
}

private void FirstReportEventHandler(object sender, PrintDocumentEventArgs e) {
    printingSettings = e.PrintDocument.PrinterSettings;
}

private void OtherReportsEventHandler(object sender, PrintDocumentEventArgs e) {
    int pageCount = e.PrintDocument.PrinterSettings.ToPage;
    e.PrintDocument.PrinterSettings = printingSettings;
    // The following line is required if the number of pages for each report varies,  
    // and you consistently need to print all pages. 
    e.PrintDocument.PrinterSettings.ToPage = pageCount;
}