Back to Devexpress

Print a Document Range

xtrareports-400021-desktop-reporting-common-features-printing-print-reports-in-wpf-print-a-document-range.md

latest1.8 KB
Original Source

Print a Document Range

  • Aug 18, 2023

This example illustrates how to print only a specific range of report pages.

Handle the PrintingSystemBase.StartPrint event using the XtraReport.PrintingSystem property. In the event handler, access the PrinterSettings object using the event argument’s PrintDocument property and specify the page numbers of the first and last pages to print.

csharp
using DevExpress.Xpf.Printing;
using DevExpress.XtraPrinting;
// ... 

private void simpleButton_Click(object sender, RoutedEventArgs e) {
    XtraReport1 report = new XtraReport1();
    report.PrintingSystem.StartPrint += PrintingSystem_StartPrint;
    PrintHelper.Print(report);
}

private void PrintingSystem_StartPrint(object sender, PrintDocumentEventArgs e) {
    // Set the page range.
    e.PrintDocument.PrinterSettings.FromPage = 1;
    e.PrintDocument.PrinterSettings.ToPage = 3;
}
vb
Imports DevExpress.Xpf.Printing
Imports DevExpress.XtraPrinting
' ...

Private Sub simpleButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim report As XtraReport1 = New XtraReport1()
    report.PrintingSystem.StartPrint += PrintingSystem_StartPrint
    PrintHelper.Print(report)
End Sub

Private Sub PrintingSystem_StartPrint(ByVal sender As Object, ByVal e As PrintDocumentEventArgs)
    ' Set the page range.
    e.PrintDocument.PrinterSettings.FromPage = 1
    e.PrintDocument.PrinterSettings.ToPage = 3
End Sub