Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get predefined paper size by PaperKind

Tags:

c#

.net

printing

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.

like image 680
Alexander G Avatar asked Jan 06 '10 14:01

Alexander G


1 Answers

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!

like image 187
Matt Jacobsen Avatar answered Sep 18 '22 10:09

Matt Jacobsen