PrintCapabilities PrintCapabilities PrintCapabilities PrintCapabilities Class

定义

定义打印机的功能。Defines the capabilities of a printer.

public ref class PrintCapabilities sealed
public sealed class PrintCapabilities
type PrintCapabilities = class
Public NotInheritable Class PrintCapabilities
继承
PrintCapabilitiesPrintCapabilitiesPrintCapabilitiesPrintCapabilities

示例

下面的示例演示如何确定特定打印机的功能, 以及如何配置打印作业以利用这些功能。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.

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

   LocalPrintServer^ localPrintServer = gcnew 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
   {
      return nullptr;
   }
   // 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()
// ---------------------- 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()
' ---------------------- GetPrintTicketFromPrinter -----------------------
''' <summary>
'''   Returns a PrintTicket based on the current default printer.</summary>
''' <returns>
'''   A PrintTicket for the current local default printer.</returns>
Private Function GetPrintTicketFromPrinter() As PrintTicket
    Dim printQueue As PrintQueue = Nothing

    Dim localPrintServer As New LocalPrintServer()

    ' Retrieving collection of local printer on user machine
    Dim localPrinterCollection As PrintQueueCollection = localPrintServer.GetPrintQueues()

    Dim localPrinterEnumerator As System.Collections.IEnumerator = localPrinterCollection.GetEnumerator()

    If localPrinterEnumerator.MoveNext() Then
        ' Get PrintQueue from first available printer
        printQueue = CType(localPrinterEnumerator.Current, PrintQueue)
    Else
        ' No printer exist, return null PrintTicket
        Return Nothing
    End If

    ' Get default PrintTicket from printer
    Dim printTicket As PrintTicket = printQueue.DefaultPrintTicket

    Dim printCapabilites As PrintCapabilities = printQueue.GetPrintCapabilities()

    ' Modify PrintTicket
    If printCapabilites.CollationCapability.Contains(Collation.Collated) Then
        printTicket.Collation = Collation.Collated
    End If

    If printCapabilites.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge) Then
        printTicket.Duplexing = Duplexing.TwoSidedLongEdge
    End If

    If printCapabilites.StaplingCapability.Contains(Stapling.StapleDualLeft) Then
        printTicket.Stapling = Stapling.StapleDualLeft
    End If

    Return printTicket
End Function ' end:GetPrintTicketFromPrinter()

注解

对象是特定类型的 XML 文档 (称为PrintCapabilities 文档) 的易于工作的表示形式。 PrintCapabilitiesA 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. 例如, 如果打印机支持彩色打印, 则文档将包含一个<PageOutputColor … >元素, 用于设置如何处理颜色输出。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. 元素依次由OutputColorCapability PrintCapabilities对象的属性表示。The element is, in turn, represented by the OutputColorCapability property of the PrintCapabilities object. 如果打印机不支持颜色, 则<PageOutputColor … >文档中没有元素, 并且OutputColorCapability属性的值为nullIf the printer does not support color, then there is no <PageOutputColor … > element in the document and the value of the OutputColorCapability property is null. PrintCapabilities 文档必须符合打印架构The PrintCapabilities document must conform to the Print Schema.

利用类, 您的应用程序可以获得打印机的功能, 而无需参与 XML Stream对象的任何直接读取。 PrintCapabilitiesThe PrintCapabilities class enables your application to obtain a printer's capabilities without having to engage in any direct reading of XML Stream objects.

适用于家庭和企业的文件和照片打印机的所有最常用功能都由PrintCapabilities类封装。All of the most popular features of file and photo printers, for both home and business, are encapsulated by the PrintCapabilities class. 打印架构定义了许多其他不太常用的功能, 并且可以对其进行扩展以处理专业打印设备的功能。But the Print Schema defines many more, less common, features and it can be extended to handle features of specialty printing devices. PrintTicket因此, 虽然和PrintCapabilities类不能被继承, 但你可以扩展打印架构来识别在PrintTicketPrintCapabilities类中不考虑的打印设备功能。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.

注意使用采用 PrintCapabilities 文档 ( Stream作为) 参数的构造函数创建对象时,整个文档将存储在对象中的非公共字段中,其中包括更少表达的XML元素PrintCapabilities不由PrintCapabilities类的任何公共属性表示的常见功能。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. 事实上, 如果生成 PrintCapabilities 文档的驱动程序使用打印架构的专用扩展, 则该私下定义的标记也将作为非公共 PrintCapabilities 文档的一部分进行存储。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.

注意

System.Printing命名空间中的类不支持在 Windows 服务或 ASP.NET 应用程序或服务中使用。Classes within the System.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.

如果要从 Windows 窗体应用程序进行打印, 请参阅System.Drawing.Printing命名空间。If you want to print from a Windows Forms application, see the System.Drawing.Printing namespace.

构造函数

PrintCapabilities(Stream) PrintCapabilities(Stream) PrintCapabilities(Stream) PrintCapabilities(Stream)

使用指定打印机功能并符合 XML 打印架构的 XML 流(其中包含 PrintCapabilities 文档)初始化 PrintCapabilities 类的新实例。Initializes a new instance of the PrintCapabilities class by using an XML stream (that contains a PrintCapabilities document) that specifies printer capabilities and complies with the XML Print Schema.

属性

CollationCapability CollationCapability CollationCapability CollationCapability

获取值的集合,这些值用于标识打印机的排序功能。Gets a collection of values that identify the collation capabilities of a printer.

DeviceFontSubstitutionCapability DeviceFontSubstitutionCapability DeviceFontSubstitutionCapability DeviceFontSubstitutionCapability

获取值的集合,这些值用于标识打印机是否可以用基于设备的字体替换基于计算机的字体,以及如何进行替换。Gets a collection of values that identify whether and how a printer can substitute device-based fonts for computer-based fonts.

DuplexingCapability DuplexingCapability DuplexingCapability DuplexingCapability

获取值的集合,这些值用于标识打印机是否可以执行双面打印,以及如何执行双面打印。Gets a collection of values that identify whether and how a printer can perform two-sided printing.

InputBinCapability InputBinCapability InputBinCapability InputBinCapability

获取值的集合,这些值用于指示使用哪个送纸盒(纸盒)。Gets a collection of values that indicate what input bin (paper tray) is used.

MaxCopyCount MaxCopyCount MaxCopyCount MaxCopyCount

获取一个值,该值指示设备在一次打印作业中所能打印的最大副本数。Gets a value indicating the maximum number of copies that the device can print in a single print job.

OrientedPageMediaHeight OrientedPageMediaHeight OrientedPageMediaHeight OrientedPageMediaHeight

获取表示页面中成像区域高度的值,其中高度表示与页面方向相对应的垂直尺寸。Gets a value indicating the height of the imageable area on a page, where height means the vertical dimension relative to the page's orientation.

OrientedPageMediaWidth OrientedPageMediaWidth OrientedPageMediaWidth OrientedPageMediaWidth

获取表示页面中成像区域宽度的值,其中宽度表示与页面方向相对应的水平尺寸。Gets a value indicating the width of the imageable area on a page, where width means the horizontal dimension relative to the page's orientation.

OutputColorCapability OutputColorCapability OutputColorCapability OutputColorCapability

获取值的集合,这些值用于指定打印机对于带有彩色和灰阶内容的打印方法。Gets a collection of values that specify the ways in which a printer can print content with color and shades of gray.

OutputQualityCapability OutputQualityCapability OutputQualityCapability OutputQualityCapability

获取值的集合,这些值用于指示打印机支持的输出质量的类型。Gets a collection of values that indicate the types of output quality the printer supports.

PageBorderlessCapability PageBorderlessCapability PageBorderlessCapability PageBorderlessCapability

获取值的集合,这些值用于指示打印机是否可以打印到介质的边缘。Gets a collection of values that indicate whether the printer can print up to the edge of the media.

PageImageableArea PageImageableArea PageImageableArea PageImageableArea

获取一个对象,该对象用于表示打印机所能使用页面的区域。Gets an object that represents the area of a page that the printer can use.

PageMediaSizeCapability PageMediaSizeCapability PageMediaSizeCapability PageMediaSizeCapability

获取 PageMediaSize 对象的集合,这些对象用于标识打印机支持的纸张和介质的尺寸。Gets a collection of PageMediaSize objects that identify the paper and media sizes that a printer supports.

PageMediaTypeCapability PageMediaTypeCapability PageMediaTypeCapability PageMediaTypeCapability

获取值的集合,这些值用于标识打印机支持的纸张和其他介质的类型。Gets a collection of values that identify what types of paper and other media a printer supports.

PageOrderCapability PageOrderCapability PageOrderCapability PageOrderCapability

获取值的集合,这些值用于指示打印机是否能够从前往后和/或从后往前打印多页文档。Gets a collection of values that indicate whether a printer is capable of printing multiple-page documents from front-to-back, back-to-front, or both ways.

PageOrientationCapability PageOrientationCapability PageOrientationCapability PageOrientationCapability

获取值的集合,这些值用于标识打印机支持的页面方向的类型。Gets a collection of values that identify what types of page orientation a printer supports.

PageResolutionCapability PageResolutionCapability PageResolutionCapability PageResolutionCapability

获取 PageResolution 对象的集合,这些对象用于标识打印机支持的页面分辨率的等级。Gets a collection of PageResolution objects that identify what levels of page resolution the printer supports.

PageScalingFactorRange PageScalingFactorRange PageScalingFactorRange PageScalingFactorRange

获取打印机可在页面中放大或缩小打印图像的最大和最小百分比。Gets the maximum and minimum percentages by which a printer can enlarge or reduce the print image on a page.

PagesPerSheetCapability PagesPerSheetCapability PagesPerSheetCapability PagesPerSheetCapability

获取整数的集合,每一个整数用于标识用户可以选择在一页纸的单面上所打印的页数。Gets a collection of integers, each identifying the number of pages that a user can choose to print on a single side of a sheet of paper.

PagesPerSheetDirectionCapability PagesPerSheetDirectionCapability PagesPerSheetDirectionCapability PagesPerSheetDirectionCapability

获取值的集合,这些值用于标识打印机支持的、用于在每一张纸的单面上呈现多页的模式。Gets a collection of values that identify what patterns a printer supports for presenting multiple pages on a single side of a sheet of paper.

PhotoPrintingIntentCapability PhotoPrintingIntentCapability PhotoPrintingIntentCapability PhotoPrintingIntentCapability

获取值的集合,这些值用于标识打印机支持的、用于打印照片的质量选项。Gets a collection of values that identify the quality options the printer supports for printing photographs.

StaplingCapability StaplingCapability StaplingCapability StaplingCapability

获取值的集合,这些值用于标识打印机支持的自动装订的类型。Gets a collection of values that identify the types of automatic stapling that a printer supports.

TrueTypeFontModeCapability TrueTypeFontModeCapability TrueTypeFontModeCapability TrueTypeFontModeCapability

获取值的集合,这些值用于标识打印机支持的、用于处理 TrueType 字体的方法。Gets a collection of values that identify the methods that a printer supports for handling TrueType fonts.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于