GDI+ PaperSize Class in VB.NET

In this article I will explain about the PaperSize Class in GDI+.
  • 2332

Most printers can use papers of more than one size (height and width). The PaperSize class is used to read and set the paper size used by a printer.

The PaperSize class represents the size of paper used in printing. This class is used by PrinterSettings through its PaperSizes property to get and set the paper sizes for the printer.

TABLE 11.2: Other PrinterSettings properties




Returns the default page settings.


Returns the page number of the first page to print. Both get and set.


Returns true if the current printer is the default printer.


Returns the angle, in degrees, by which the portrait orientation is rotated to, produces the landscape orientation. Valid rotation values are 90 and 27 degrees. If landscape is not supported, the only valid rotation value is 0 degrees.


Returns the maximum value of FromPage or ToPage that can be selected in a print dialog. Both get and set.


Returns the minimum value of FromPage to ToPage that can be selected in a print dialog. Both get and set.


Returns the page numbers that the user has specified to be printed. Both get and set.


Returns a value indicating whether the printing output is sent to a file instead of a port. Both get and set.


Returns the page number of the last page to print. Both get and set.

The PaperSize class has four properties: Height, Kind, PaperName, and Width.Height, Width and PaperName have both get and set access. The Height and Width properties are used to get and set the paper's height and width, respectively, in hundredths of an inch. The PaperName property is used to get and set the name of the type of paper, but it can be used only when the Kind property is set to Custom. The Kind property returns the type of paper.

We can construct custom paper size using the PaperSize clas. Listing 11.12 reads the PaperSize properties.

LISTING 11.12: Reading PaperSize properties

        Dim ps As New PrinterSettings()
        Console.WriteLine("Paper Sizes")

        For Each psize As PaperSize In ps.PaperSizes
            Dim str1 As String = psize.Kind.ToString()
            Dim str2 As String = psize.PaperName.ToString()
            Dim str3 As String = psize.Height.ToString()
            Dim str4 As String = psize.Width.ToString()

The PaperSource Class

The PaperSource class specifies the paper tray from which the printer retrieves the paper for the current printing task. This class is used by PritnerSettings through its PaperSoruces property to get and set the paper source trays that a re available on the printer. The PaperSize class has two properties: Kind and SourceName. The Kind property returns an enumerated value for the paper source, and SoruceName returns the name of the paper source as a string.

Listing 11.13 reads all the paper sources and displays them in a message box.

LISTING 11.13: Reading paper sources

        Dim ps As New PrinterSettings()

        For Each p As PaperSource In ps.PaperSources

The PrinterResolutionKind Enumeration

The PrinterResolutionKind enumeration specifies a printer resolution, as described in Table 11.3. This enumeration is used by the PrinterResolution, PrinterSettings, and PageSettings classes.

PrinterSettings Collection Classes

Besides the PrinterSetting class, the System.Drawing.Printing namespace provides three PrinterSettings collection classes. These collection classes provide members to count total items in a collection, and to add item to and remove items from a collection. The classes are:

  1. PrinterSettings.PaperSizeCollection. A printer may support different kinds of papers, including papers of different sizes. This class returns a collection including all paper sizes supported by the printer. PaperSizeCollection contains PaperSizes objects.
  2. PrinterSettings.PaperSourceCollection.A printer may support different paper sources (trays). This class represents a collection of paper sources (trays) provided by a printer. PaperSourceCollection is available via the PaperSoruces property and contains PaperSource objects.
  3. PrinterSettings.PrinterResolution.Collection. A printer may support different resolutions. This class represents a collection of resolutions supported by a printer. PrinterResolutionsCollection is accessible via the PrinterResoultions property and contains PrinterResoultion objects.

TABLE 11.3: PrinterResolutionKind members




Custom resolution


Draft-quality resolution


High resolution


Low resolution


Medium resolution

All these collection classes provide Count and Item properties. The Count property returns the total number of items in a collection, and the Item property returns the item at the specified index. We will use these classes in our samples.


Hope the article would have helped you in understanding the PaperSize Class in GDI+. Read other articles on GDI+ on the website.


More Articles

© 2019 DotNetHeaven. All rights reserved.