PrintQueue.GetPrintCapabilities 方法

定义

获取一个 PrintCapabilities 对象,该对象标识打印机或设备的功能,如是否可彩色打印或双面打印。Gets a PrintCapabilities object that identifies the capabilities of the printer or device, such as whether it prints in color or is capable of two-sided printing.

重载

GetPrintCapabilities()

获取用于标识打印机功能的 PrintCapabilities 对象。Gets a PrintCapabilities object that identifies the capabilities of the printer.

GetPrintCapabilities(PrintTicket)

获取用于标识打印机功能的 PrintCapabilities 对象。Gets a PrintCapabilities object that identifies the capabilities of the printer.

GetPrintCapabilities()

获取用于标识打印机功能的 PrintCapabilities 对象。Gets a PrintCapabilities object that identifies the capabilities of the printer.

public:
 System::Printing::PrintCapabilities ^ GetPrintCapabilities();
public System.Printing.PrintCapabilities GetPrintCapabilities ();
member this.GetPrintCapabilities : unit -> System.Printing.PrintCapabilities
Public Function GetPrintCapabilities () As PrintCapabilities

返回

用于指定打印机可执行和不可执行的操作(如双面复印或自动装订)的 PrintCapabilities 对象。A PrintCapabilities object that specifies what the printer can and cannot do, such as two-sided coping or automatic stapling.

异常

未能检索到 PrintCapabilities 对象。The PrintCapabilities object could not be retrieved.

示例

下面的示例演示如何在合并两个打印票证时使用此方法。The following example shows how to use this method while merging two print tickets.

/// <summary>
/// Changes the user-default PrintTicket setting of the specified print queue.
/// </summary>
/// <param name="queue">the printer whose user-default PrintTicket setting needs to be changed</param>
static private void ChangePrintTicketSetting(PrintQueue queue)
{
    //
    // Obtain the printer's PrintCapabilities so we can determine whether or not
    // duplexing printing is supported by the printer.
    //
    PrintCapabilities printcap = queue.GetPrintCapabilities();

    //
    // The printer's duplexing capability is returned as a read-only collection of duplexing options
    // that can be supported by the printer. If the collection returned contains the duplexing
    // option we want to set, it means the duplexing option we want to set is supported by the printer,
    // so we can make the user-default PrintTicket setting change.
    //
    if (printcap.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge))
    {
        //
        // To change the user-default PrintTicket, we can first create a delta PrintTicket with
        // the new duplexing setting.
        //
        PrintTicket deltaTicket = new PrintTicket();
        deltaTicket.Duplexing = Duplexing.TwoSidedLongEdge;

        //
        // Then merge the delta PrintTicket onto the printer's current user-default PrintTicket,
        // and validate the merged PrintTicket to get the new PrintTicket we want to set as the
        // printer's new user-default PrintTicket.
        //
        ValidationResult result = queue.MergeAndValidatePrintTicket(queue.UserPrintTicket, deltaTicket);

        //
        // The duplexing option we want to set could be constrained by other PrintTicket settings
        // or device settings. We can check the validated merged PrintTicket to see whether the
        // the validation process has kept the duplexing option we want to set unchanged.
        //
        if (result.ValidatedPrintTicket.Duplexing == Duplexing.TwoSidedLongEdge)
        {
            //
            // Set the printer's user-default PrintTicket and commit the set operation.
            //
            queue.UserPrintTicket = result.ValidatedPrintTicket;
            queue.Commit();
            Console.WriteLine("PrintTicket new duplexing setting is set on '{0}'.", queue.FullName);
        }
        else
        {
            //
            // The duplexing option we want to set has been changed by the validation process
            // when it was resolving setting constraints.
            //
            Console.WriteLine("PrintTicket new duplexing setting is constrained on '{0}'.", queue.FullName);
        }
    }
    else
    {
        //
        // If the printer doesn't support the duplexing option we want to set, skip it.
        //
        Console.WriteLine("PrintTicket new duplexing setting is not supported on '{0}'.", queue.FullName);
    }
}
''' <summary>
''' Changes the user-default PrintTicket setting of the specified print queue.
''' </summary>
''' <param name="queue">the printer whose user-default PrintTicket setting needs to be changed</param>
Private Shared Sub ChangePrintTicketSetting(ByVal queue As PrintQueue)
    '
    ' Obtain the printer's PrintCapabilities so we can determine whether or not
    ' duplexing printing is supported by the printer.
    '
    Dim printcap As PrintCapabilities = queue.GetPrintCapabilities()

    '
    ' The printer's duplexing capability is returned as a read-only collection of duplexing options
    ' that can be supported by the printer. If the collection returned contains the duplexing
    ' option we want to set, it means the duplexing option we want to set is supported by the printer,
    ' so we can make the user-default PrintTicket setting change.
    '
    If printcap.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge) Then
        '
        ' To change the user-default PrintTicket, we can first create a delta PrintTicket with
        ' the new duplexing setting.
        '
        Dim deltaTicket As New PrintTicket()
        deltaTicket.Duplexing = Duplexing.TwoSidedLongEdge

        '
        ' Then merge the delta PrintTicket onto the printer's current user-default PrintTicket,
        ' and validate the merged PrintTicket to get the new PrintTicket we want to set as the
        ' printer's new user-default PrintTicket.
        '
        Dim result As ValidationResult = queue.MergeAndValidatePrintTicket(queue.UserPrintTicket, deltaTicket)

        '
        ' The duplexing option we want to set could be constrained by other PrintTicket settings
        ' or device settings. We can check the validated merged PrintTicket to see whether the
        ' the validation process has kept the duplexing option we want to set unchanged.
        '
        If result.ValidatedPrintTicket.Duplexing = Duplexing.TwoSidedLongEdge Then
            '
            ' Set the printer's user-default PrintTicket and commit the set operation.
            '
            queue.UserPrintTicket = result.ValidatedPrintTicket
            queue.Commit()
            Console.WriteLine("PrintTicket new duplexing setting is set on '{0}'.", queue.FullName)
        Else
            '
            ' The duplexing option we want to set has been changed by the validation process
            ' when it was resolving setting constraints.
            '
            Console.WriteLine("PrintTicket new duplexing setting is constrained on '{0}'.", queue.FullName)
        End If
    Else
        '
        ' If the printer doesn't support the duplexing option we want to set, skip it.
        '
        Console.WriteLine("PrintTicket new duplexing setting is not supported on '{0}'.", queue.FullName)
    End If
End Sub

安全性

PrintingPermission
获取打印功能的权限。for permission to get print capabilities. 关联的枚举: DefaultPrintingAssociated enumeration: DefaultPrinting

GetPrintCapabilities(PrintTicket)

获取用于标识打印机功能的 PrintCapabilities 对象。Gets a PrintCapabilities object that identifies the capabilities of the printer.

public:
 System::Printing::PrintCapabilities ^ GetPrintCapabilities(System::Printing::PrintTicket ^ printTicket);
[System.Security.SecurityCritical]
public System.Printing.PrintCapabilities GetPrintCapabilities (System.Printing.PrintTicket printTicket);
member this.GetPrintCapabilities : System.Printing.PrintTicket -> System.Printing.PrintCapabilities

参数

printTicket
PrintTicket

提供打印功能报告根据的打印票证。A print ticket that provides the basis on which the print capabilities are reported.

返回

用于指定打印机可执行和不可执行的操作(如双面复印或自动装订)的 PrintCapabilities 对象。A PrintCapabilities object that specifies what the printer can and cannot do, such as two-sided coping or automatic stapling.

属性

异常

未能检索到 PrintCapabilities 对象。The PrintCapabilities object could not be retrieved.

printTicket 不符合标准格式。printTicket is not well-formed.

注解

PrintTicket 参数将用作构造 PrintCapabilities 对象的基础。The PrintTicket parameter is used as the basis on which to construct the PrintCapabilities object. 例如,假设打印机仅支持输入纸盒1中的媒体类型 A 和 B,并且仅支持输入纸盒2中的媒体类型 C。For example, suppose the printer supported only media types A and B from input bin 1 and it only supported media type C from input bin 2. 如果 printTicket 参数指定了输入纸盒1,则返回的 PrintCapabilities 对象将包含所有三种媒体类型,但它会将类型 C 报告为 "约束"。If the printTicket parameter specified input bin 1, then the PrintCapabilities object that is returned would include all three media types, but it would report type C as "constrained." 如果 printTicket 参数指定了输入纸盒2,则返回的 PrintCapabilities 对象将包含所有三种媒体类型,但会将类型 A 和 B 报告为 "约束"。If the printTicket parameter specified input bin 2, then the PrintCapabilities object that is returned would include all three media types, but it would report types A and B as "constrained." 有关约束的详细信息,请参阅打印架构See the Print Schema for more information on constraints.

如果 null``printTicket,则使用 UserPrintTicketIf printTicket is null, the UserPrintTicket is used.

安全性

PrintingPermission
获取打印功能的权限。for permission to get print capabilities. 关联的枚举: DefaultPrintingAssociated enumeration: DefaultPrinting

适用于