Back to Devexpress

Specify the Paper Source and Printer Resolution

xtrareports-7065-desktop-reporting-common-features-printing-winforms-reporting-print-api-specify-the-paper-source-and-printer-resolution.md

latest2.9 KB
Original Source

Specify the Paper Source and Printer Resolution

  • Aug 18, 2023

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

To do this, assign a report instance to a ReportPrintTool, and handle the PrintingSystemBase.StartPrint event of the Print Tool’s PrintToolBase.PrintingSystem.

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

private void button1_Click(object sender, System.EventArgs e) {
    ReportPrintTool printTool = new ReportPrintTool(new XtraReport1());
    printTool.PrintingSystem.StartPrint += PrintingSystem_StartPrint;
    printTool.PrintDialog();
}

void PrintingSystem_StartPrint(object sender, PrintDocumentEventArgs e) {
    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;
        }

    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 DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
Imports System.Drawing.Printing
' ...

Private Sub button1_Click(sender As Object, e As System.EventArgs)
    Dim printTool As New ReportPrintTool(New XtraReport1())
    AddHandler printTool.PrintingSystem.StartPrint, _ 
        AddressOf PrintingSystem_StartPrint
    printTool.PrintDialog()
End Sub

Private Sub PrintingSystem_StartPrint(sender As Object, e As PrintDocumentEventArgs)
    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

    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