Export (0) Print
Expand All

PrintCapabilities Class

Defines the capabilities of a printer. This class cannot be inherited.

Namespace: System.Printing
Assembly: ReachFramework (in reachframework.dll)

public sealed class PrintCapabilities
public final class PrintCapabilities
public final class PrintCapabilities
You cannot use this managed class in XAML.

A PrintCapabilities object is an easy-to-work-with representation of a certain type of XML document called a PrintCapabilities document. The latter is a snapshot of all of a printer's capabilities and their current settings. For example, if the printer supports color printing, then the document would have a <PageOutputColor … > element that sets out how color output will be handled. The element is, in turn, represented by the OutputColorCapability property of the PrintCapabilities object. If the printer does not support color, then there is no <PageOutputColor … > element in the document and the value of the OutputColorCapability property is a null reference (Nothing in Visual Basic). The PrintCapabilities document must conform to the Print Schema.

The PrintCapabilities class enables your application to obtain a printer's capabilities without having to engage in any direct reading of XML Stream objects.

All of the most popular features of home and business file and photo printers are represented by properties of PrintCapabilities the class. But the Print Schema defines many more, less common, features and it can be extended to handle features of specialty printing devices. So, although the PrintTicket and PrintCapabilities classes cannot be inherited, you can extend the Print Schema to recognize print device features that are not accounted for in the PrintTicket or PrintCapabilities classes. For more information see How to: Extend the Print Schema and Create New Print System Classes.

Note   When the PrintCapabilities object is created with the constructor that takes a PrintCapabilities document (as a Stream) parameter, that entire document is stored in a non-public field in the object, including the XML elements within it that express less common features that are not represented by any of the public properties of the PrintCapabilities class. In fact, if the driver that produced the PrintCapabilities document is using a private extension of the Print Schema, that privately defined markup is also stored as part of the non-public PrintCapabilities document.

The following example shows how to determine the capabilities of a specific printer and how to configure a print job to take advantage of them. For the complete example, see Creating an XPS Document Sample.

// ---------------------- GetPrintTicketFromPrinter -----------------------
/// <summary>
///   Returns a PrintTicket based on the current default printer.</summary>
/// <returns>
///   A PrintTicket for the current local default printer.</returns>
private PrintTicket GetPrintTicketFromPrinter()
{
    PrintQueue printQueue = null;

    LocalPrintServer localPrintServer = new LocalPrintServer();

    // Retrieving collection of local printer on user machine
    PrintQueueCollection localPrinterCollection =
        localPrintServer.GetPrintQueues();

    System.Collections.IEnumerator localPrinterEnumerator =
        localPrinterCollection.GetEnumerator();

    if (localPrinterEnumerator.MoveNext())
    {
        // Get PrintQueue from first available printer
        printQueue = (PrintQueue)localPrinterEnumerator.Current;
    }
    else
    {
        // No printer exist, return null PrintTicket
        return null;
    }

    // Get default PrintTicket from printer
    PrintTicket printTicket = printQueue.DefaultPrintTicket;

    PrintCapabilities printCapabilites = printQueue.GetPrintCapabilities();

    // Modify PrintTicket
    if (printCapabilites.CollationCapability.Contains(Collation.Collated))
    {
        printTicket.Collation = Collation.Collated;
    }

    if ( printCapabilites.DuplexingCapability.Contains(
            Duplexing.TwoSidedLongEdge) )
    {
        printTicket.Duplexing = Duplexing.TwoSidedLongEdge;
    }

    if (printCapabilites.StaplingCapability.Contains(Stapling.StapleDualLeft))
    {
        printTicket.Stapling = Stapling.StapleDualLeft;
    }

    return printTicket;
}// end:GetPrintTicketFromPrinter()

System.Object
  System.Printing.PrintCapabilities

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft