Built test page for testing tray output for debugging in main app.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
|
||||
class TrayTest
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
var printerName = "Brother HL-L6415DW series Printer";
|
||||
var trayNumbers = new int[] { 1, 2, 256, 257, 270 }; // Tray 1, 2, 3, 4, 5
|
||||
var currentPage = 0;
|
||||
|
||||
var printDoc = new PrintDocument
|
||||
{
|
||||
PrinterSettings = {
|
||||
PrinterName = printerName,
|
||||
Duplex = Duplex.Simplex // Force single-sided
|
||||
}
|
||||
};
|
||||
|
||||
// QueryPageSettings fires BEFORE PrintPage - this is where we set the tray
|
||||
printDoc.QueryPageSettings += (sender, e) =>
|
||||
{
|
||||
if (e.PageSettings == null)
|
||||
return;
|
||||
|
||||
var trayNumber = trayNumbers[currentPage];
|
||||
|
||||
// Set the tray for this page
|
||||
PaperSource? paperSource = null;
|
||||
foreach (PaperSource source in printDoc.PrinterSettings.PaperSources)
|
||||
{
|
||||
if (source.RawKind == trayNumber)
|
||||
{
|
||||
paperSource = source;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (paperSource != null)
|
||||
{
|
||||
e.PageSettings.PaperSource = paperSource;
|
||||
Console.WriteLine($"Page {currentPage + 1}: Using tray {trayNumber} ({paperSource.SourceName})");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Page {currentPage + 1}: WARNING - Tray {trayNumber} not found!");
|
||||
}
|
||||
};
|
||||
|
||||
printDoc.PrintPage += (sender, e) =>
|
||||
{
|
||||
if (e.Graphics == null)
|
||||
return;
|
||||
|
||||
// Draw the page number
|
||||
var font = new Font("Courier New", 24, FontStyle.Bold);
|
||||
var text = $"Page #{currentPage + 1}";
|
||||
e.Graphics.DrawString(text, font, Brushes.Black, 100, 100);
|
||||
|
||||
currentPage++;
|
||||
e.HasMorePages = currentPage < trayNumbers.Length;
|
||||
};
|
||||
|
||||
Console.WriteLine($"Printing 5 pages to {printerName}...");
|
||||
printDoc.Print();
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<EnableDefaultCompileItems>true</EnableDefaultCompileItems>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user