xtrareports-400022-desktop-reporting-common-features-printing-print-reports-in-wpf-specify-the-paper-source-and-printer-resolution.md
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.
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;
}
}
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