Reputation: 3512
Can this be done programmatically, and without creating a custom PaperSize but using the predefined sizes? The printer is known to support the legal size paper.
Is there a more elegant solution than looping through the printer's paper sizes and scanning for Legal
substring?
UPDATE This is what I ended up doing:
For i = 0 To PrintDocument1.PrinterSettings.PaperSizes.Count - 1
If PrintDocument1.PrinterSettings.PaperSizes(i).RawKind = PaperKind.Legal Then
PrintDocument1.DefaultPageSettings.PaperSize = PrintDocument1.PrinterSettings.PaperSizes(i)
Exit For
End If
Next
Upvotes: 1
Views: 1619
Reputation: 34408
I know C# better than VB.NET and in C# I'd do this using LINQ. For my own interest at least here's two attempts at VB.NET LINQ syntax:
Dim paperSize as PaperSize = _
From ps in PrintDocument1.PrinterSettings.PaperSizes _
Where ps.RawKind = PaperKind.Legal _
Select ps Take 1
If paperSize IsNot Nothing
DocPrint.DefaultPageSettings.PaperSize = paperSize
End If
or
Dim paperSize = PrintDocument1.PrinterSettings.PaperSizes _
.FirstOrDefault(Function(ps) ps.RawKind = PaperKind.Legal)
If paperSize IsNot Nothing
DocPrint.DefaultPageSettings.PaperSize = paperSize
End If
I'm guessing the syntax so neither of these might work and I've ended up with at least as many lines of code, but it saves writing a loop.
Upvotes: 2
Reputation: 2350
It is a default entry in the PaperKind enum:
PaperLegal
(Legal, 8 1/2- by 14-inches.)
Upvotes: 3