I need to get paper size by System.Drawing.Printing.PaperKind. Are there any predefined values? I don't want to hardcode or calculate paper sizes, I just want to get it programmatically. Thanks.
A subset of predefined values can be had by iterating over a PrinterSettings.PaperSizes
collection.
Our application has the user select a printer, providing us with a PrinterSettings
object. Contained within PrinterSettings
is a list of PaperSize
's supported by the printer - not everything (note that the XPS Document Driver (win7) supports all sizes).
In our case this subset of supported sizes is all we need. A user specified PaperKind
is passed to our printing code, and it goes through our PrinterSettings
object until it either finds the user's selection or gives up and uses a default.
In the example below you can see that the PaperSize
objects are correctly filled.
PrinterSettings settings = new PrinterSettings();
foreach (PaperSize size in settings.PaperSizes)
Debug.WriteLine(size);
It's only a subset, but maybe that's also enough for you. the printing APIs in .NET are really unclear and msdn isn't really much help... Hopefully it puts you on the right track!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With