Hello,
Thank you for your inquiry.
Based on your description, I understand that you are looking for a way to select a printer tray based on the left or right offset of the printer. The System.Drawing.Printing.PrinterSettings class supports retrieving the left or right offset of the printer settings. Please refer to the code snippet below to implement this requirement.
- Code: Select all
// Create a new PdfDocument object
PdfDocument doc = new PdfDocument();
// Load the PDF file from the specified path
doc.LoadFromFile(@"input.pdf");
// Set the print settings for the document: color, landscape orientation, and duplex printing
doc.PrintSettings.Color = true;
doc.PrintSettings.Landscape = true;
doc.PrintSettings.Duplex = Duplex.Horizontal;
// Create a new PrinterSettings object and specify the printer name
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.PrinterName = "printer name";
// Set the left margin value for the default page settings of the printer
//printerSettings.DefaultPageSettings.Margins.Left = 12;
// Get the left and right margin values from the default page settings
int left = printerSettings.DefaultPageSettings.Margins.Left;
int right = printerSettings.DefaultPageSettings.Margins.Right;
// Set the printer name for the print settings of the document
doc.PrintSettings.PrinterName = printerSettings.PrinterName;
// Attach an event handler to the PaperSettings event of the PrintSettings
doc.PrintSettings.PaperSettings += delegate (object sender1, PdfPaperSettingsEventArgs e1)
{
// Check if the left margin is greater than 0
if (left > 0)
{
// Set the current paper source to the first available paper source
e1.CurrentPaperSource = e1.PaperSources[0];
}
else
{
// Set the current paper source to the second available paper source
e1.CurrentPaperSource = e1.PaperSources[1];
}
};
// Print the document using the specified printer and settings
doc.Print();
If the provided code does not meet your requirements, please provide more specific details about your needs. We would be happy to assist you further.
Sincerely,
Annika
E-iceblue support team