Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining

System.Drawing.Printing Namespace

The System.Drawing.Printing namespace provides print-related services for Windows Forms applications.

Typically, when you print from a Windows Forms application, you create a new instance of the PrintDocument class, set properties, such as DefaultPageSettings and PrinterSettings, that describe how to print, and call the Print method to actually print the document. Calling the PrintDocument.Print method raises the PrintDocument.PrintPage event, which should be handled to perform the document layout for printing.

Use the Graphics property of the PrintPageEventArgs object obtained from the PrintDocument.PrintPage event to specify the output to print. If you are printing a text file, use StreamReader to read one line at a time from the stream and call the DrawString method to draw the line in the graphics object. For more information about this process, see the Graphics and StreamReader classes. You can view an example of printing a text document in the PrintDocument class overview topic.

Note Note

The DrawText methods of the TextRenderer class are not supported for printing. Instead, use the DrawString methods of the Graphics class.

When implemented in a derived class, the PrintController controls how a PrintDocument is printed. The PrintDocument.Print method invokes the print controller's OnStartPrint, OnEndPrint, OnStartPage, and OnEndPage methods, which in turn tell the printer how to print the document. For more information about printing dialog boxes, see PrintDialog and PageSetupDialog.

The print-preview process uses a specialized print controller, dialog box, and control. For an example of such a print controller and dialog box, see PreviewPrintController, PrintPreviewDialog, and PrintPreviewControl.

Caution note Caution

Classes within the System.Drawing.Printing namespace are not supported for use within a Windows service or ASP.NET application or service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.

If you want to print from a Windows Presentation Foundation (WPF) application, see the System.Printing namespace.

  Class Description
Public class InvalidPrinterException Represents the exception that is thrown when you try to access a printer using printer settings that are not valid.
Public class Margins Specifies the dimensions of the margins of a printed page.
Public class MarginsConverter Provides a MarginsConverter for Margins.
Public class PageSettings Specifies settings that apply to a single, printed page.
Public class PaperSize Specifies the size of a piece of paper.
Public class PaperSource Specifies the paper tray from which the printer gets paper.
Public class PreviewPageInfo Specifies print preview information for a single page. This class cannot be inherited.
Public class PreviewPrintController Specifies a print controller that displays a document on a screen as a series of images.
Public class PrintController Controls how a document is printed, when printing from a Windows Forms application.
Public class PrintDocument Defines a reusable object that sends output to a printer, when printing from a Windows Forms application.
Public class PrinterResolution Represents the resolution supported by a printer.
Public class PrinterSettings Specifies information about how a document is printed, including the printer that prints it, when printing from a Windows Forms application.
Public class PrinterSettings.PaperSizeCollection Contains a collection of PaperSize objects.
Public class PrinterSettings.PaperSourceCollection Contains a collection of PaperSource objects.
Public class PrinterSettings.PrinterResolutionCollection Contains a collection of PrinterResolution objects.
Public class PrinterSettings.StringCollection Infrastructure. Contains a collection of String objects.
Public class PrinterUnitConvert Specifies a series of conversion methods that are useful when interoperating with the Win32 printing API. This class cannot be inherited.
Public class PrintEventArgs Provides data for the BeginPrint and EndPrint events.
Public class PrintingPermission Controls access to printers. This class cannot be inherited.
Public class PrintingPermissionAttribute Allows declarative printing permission checks.
Public class PrintPageEventArgs Provides data for the PrintPage event.
Public class QueryPageSettingsEventArgs Provides data for the QueryPageSettings event.
Public class StandardPrintController Specifies a print controller that sends information to a printer.

  Delegate Description
Public delegate PrintEventHandler Represents the method that will handle the BeginPrint or EndPrint event of a PrintDocument.
Public delegate PrintPageEventHandler Represents the method that will handle the PrintPage event of a PrintDocument.
Public delegate QueryPageSettingsEventHandler Represents the method that handles the QueryPageSettings event of a PrintDocument.

  Enumeration Description
Public enumeration Duplex Specifies the printer's duplex setting.
Public enumeration PaperKind Specifies the standard paper sizes.
Public enumeration PaperSourceKind Standard paper sources.
Public enumeration PrintAction Specifies the type of print operation occurring.
Public enumeration PrinterResolutionKind Specifies a printer resolution.
Public enumeration PrinterUnit Specifies several of the units of measure used for printing.
Public enumeration PrintingPermissionLevel Specifies the type of printing that code is allowed to do.
Public enumeration PrintRange Specifies the part of the document to print.
© 2015 Microsoft