Back to Devexpress

Specify the Paper Source and Printer Resolution

xtrareports-400022-desktop-reporting-common-features-printing-print-reports-in-wpf-specify-the-paper-source-and-printer-resolution.md

latest3.4 KB
Original Source

Specify the Paper Source and Printer Resolution

  • Aug 18, 2023
  • 2 minutes to read

This example demonstrates how to select the paper source and set the printer resolution programmatically.

Handle the PrintingSystemBase.StartPrint event using the XtraReport.PrintingSystem property. In the event handler, choose the paper source and printer resolution using the PrintDocument.PrinterSettings property, and provide the selected values to the PrintDocument.DefaultPageSettings property.

csharp
using System.Drawing.Printing;
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) {
    // Select a paper source.
    for (int i = 0; i < e.PrintDocument.PrinterSettings.PaperSources.Count; i++)
        if (e.PrintDocument.PrinterSettings.PaperSources[i].Kind ==
            PaperSourceKind.TractorFeed) {
            e.PrintDocument.DefaultPageSettings.PaperSource =
                e.PrintDocument.PrinterSettings.PaperSources[i];
            break;
        }
    // Select a printer resolution.
    for (int i = 0; i < e.PrintDocument.PrinterSettings.PrinterResolutions.Count; i++)
        if (e.PrintDocument.PrinterSettings.PrinterResolutions[i].Kind ==
            PrinterResolutionKind.High) {
            e.PrintDocument.DefaultPageSettings.PrinterResolution =
                e.PrintDocument.PrinterSettings.PrinterResolutions[i];
            break;
        }
}
vb
Imports System.Drawing.Printing
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)
    ' Select a paper source.
    For i As Integer = 0 To e.PrintDocument.PrinterSettings.PaperSources.Count - 1
        If e.PrintDocument.PrinterSettings.PaperSources(i).Kind = PaperSourceKind.TractorFeed Then
            e.PrintDocument.DefaultPageSettings.PaperSource = e.PrintDocument.PrinterSettings.PaperSources(i)
            Exit For
        End If
    Next
    ' Select a printer resolution.
    For i As Integer = 0 To e.PrintDocument.PrinterSettings.PrinterResolutions.Count - 1
        If e.PrintDocument.PrinterSettings.PrinterResolutions(i).Kind = PrinterResolutionKind.High Then
            e.PrintDocument.DefaultPageSettings.PrinterResolution = e.PrintDocument.PrinterSettings.PrinterResolutions(i)
            Exit For
        End If
    Next
End Sub