PrintQueue.MergeAndValidatePrintTicket 方法

定义

合并两种 PrintTicket,保证所得的 PrintTicket 有效且不请求打印机所不支持的任何打印功能。Merges two PrintTickets and guarantees that the resulting PrintTicket is valid and does not ask for any printing functionality that the printer does not support.

重载

MergeAndValidatePrintTicket(PrintTicket, PrintTicket)

合并两种 PrintTicket,保证所得的 PrintTicket 有效且不请求打印机所不支持的任何打印功能。Merges two PrintTickets and guarantees that the resulting PrintTicket is valid and does not ask for any printing functionality that the printer does not support.

MergeAndValidatePrintTicket(PrintTicket, PrintTicket, PrintTicketScope)

合并两种 PrintTicket,保证所得的 PrintTicket 有效,不请求打印机所不支持的任何打印功能,且限于指定的作用域。Merges two PrintTickets and guarantees that the resulting PrintTicket is valid, does not ask for any printing functionality that the printer does not support, and is limited to the specified scope.

MergeAndValidatePrintTicket(PrintTicket, PrintTicket)

合并两种 PrintTicket,保证所得的 PrintTicket 有效且不请求打印机所不支持的任何打印功能。Merges two PrintTickets and guarantees that the resulting PrintTicket is valid and does not ask for any printing functionality that the printer does not support.

public:
 System::Printing::ValidationResult MergeAndValidatePrintTicket(System::Printing::PrintTicket ^ basePrintTicket, System::Printing::PrintTicket ^ deltaPrintTicket);
public System.Printing.ValidationResult MergeAndValidatePrintTicket (System.Printing.PrintTicket basePrintTicket, System.Printing.PrintTicket deltaPrintTicket);
member this.MergeAndValidatePrintTicket : System.Printing.PrintTicket * System.Printing.PrintTicket -> System.Printing.ValidationResult
Public Function MergeAndValidatePrintTicket (basePrintTicket As PrintTicket, deltaPrintTicket As PrintTicket) As ValidationResult

参数

basePrintTicket
PrintTicket

第一种打印票证。The first print ticket.

deltaPrintTicket
PrintTicket

第二种打印票证。The second print ticket. 它可以是 nullThis can be null.

返回

一个 ValidationResult,其中包括合并的 PrintTicket 和一个指示,该指示表明是否为了保证可行性而不得不更改其任何设置。A ValidationResult that includes the merged PrintTicket and an indication of whether any of its settings had to be changed to guarantee viability.

异常

至少有一个输入打印票证无效。At least one of the input print tickets is not valid.

basePrintTicketnullThe basePrintTicket is null.

验证、合并和可行性检查操作失败。The validation, merger, and viability checking operation failed.

示例

下面的示例演示如何使用此方法来合并两个打印票证并响应返回的 ValidationResultThe following example shows how to use this method to merge two print tickets and respond to the ValidationResult that is returned.

/// <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

注解

方法生成可行的打印票证;也就是说,不请求打印机不支持打印功能的票证。The method produces a viable print ticket; that is, a ticket that does not request printing features that the printer does not support. 方法首先根据打印架构验证两个输入打印票证。The method first validates the two input print tickets against the Print Schema. 如果两者都无效,则会引发异常。If either is invalid, an exception is thrown.

然后合并这两个票证。The two tickets are then merged. 如果特定属性的值不同,则生成的合并票证最初使用增量票证的值。If they have different values for a particular property then the resulting merged ticket initially uses the value of the delta ticket.

然后,根据打印机的实际功能检查合并的票证。The merged ticket is then checked against the actual capabilities of the printer. 如果票证中的任何设置与打印机功能不兼容,则打印机驱动程序将使用所需的任何逻辑更改这些设置。If any settings in the ticket are incompatible with the printer's capabilities, then the printer driver changes those settings by using whatever logic it wants. 通常情况下,它会将用户或打印机的默认值替换为设置。Typically, it substitutes the user's or printer's default value for the setting. 驱动程序的替换值源与 basePrintTicket的票证不同,则合并的票证可能具有与这两个输入票证不同的设置。It the driver's source of substitute values is not the same ticket as basePrintTicket, then the merged ticket might have some settings that are different from both of the input tickets. 如果打印机驱动程序必须更改任何设置,则会在 ValidationResultConflictStatus 属性中报告这一事实。If the printer driver has to change any settings then this fact is reported in the ConflictStatus property of the ValidationResult.

若要基于打印队列的默认设置进行合并和验证,应将 basePrintTicket 设置为 DefaultPrintTicketUserPrintTicketTo merge and validate based on a print queue's default settings, you should set basePrintTicket to the DefaultPrintTicket or the UserPrintTicket.

deltaPrintTicket 参数可以是 null,在这种情况下,将对 basePrintTicket 进行验证、检查可行性并返回,并可能会发生更改。The deltaPrintTicket parameter can be null, in which case the basePrintTicket is validated, checked for viability, and returned, possibly with changes.

MergeAndValidatePrintTicket的此重载,返回的 ValidationResult 中的 deltaPrintTicketPrintTicket 都具有作业范围。With this overload of MergeAndValidatePrintTicket, both the deltaPrintTicket and the PrintTicket in the ValidationResult that is returned have job wide scope. 若要指定不同的作用域,请使用此方法的其他重载。To specify a different scope use the other overload of this method.

MergeAndValidatePrintTicket(PrintTicket, PrintTicket, PrintTicketScope)

合并两种 PrintTicket,保证所得的 PrintTicket 有效,不请求打印机所不支持的任何打印功能,且限于指定的作用域。Merges two PrintTickets and guarantees that the resulting PrintTicket is valid, does not ask for any printing functionality that the printer does not support, and is limited to the specified scope.

public:
 System::Printing::ValidationResult MergeAndValidatePrintTicket(System::Printing::PrintTicket ^ basePrintTicket, System::Printing::PrintTicket ^ deltaPrintTicket, System::Printing::PrintTicketScope scope);
public System.Printing.ValidationResult MergeAndValidatePrintTicket (System.Printing.PrintTicket basePrintTicket, System.Printing.PrintTicket deltaPrintTicket, System.Printing.PrintTicketScope scope);
member this.MergeAndValidatePrintTicket : System.Printing.PrintTicket * System.Printing.PrintTicket * System.Printing.PrintTicketScope -> System.Printing.ValidationResult
Public Function MergeAndValidatePrintTicket (basePrintTicket As PrintTicket, deltaPrintTicket As PrintTicket, scope As PrintTicketScope) As ValidationResult

参数

basePrintTicket
PrintTicket

第一种打印票证。The first print ticket.

deltaPrintTicket
PrintTicket

第二种打印票证。The second print ticket. 它可以是 nullThis can be null.

scope
PrintTicketScope

用于表示 deltaPrintTicket 的作用域和 ValidationResult 中返回的打印票证的作用域是一个页面、文档,还是整个作业的值。A value indicating whether the scope of deltaPrintTicket, and the scope of the print ticket returned in the ValidationResult, is a page, a document, or the whole job.

返回

一个 ValidationResult,其中包括合并的 PrintTicket 和一个指示,该指示表明是否为了保证可行性而不得不更改其任何设置。A ValidationResult that includes the merged PrintTicket and an indication of whether any of its settings had to be changed to guarantee viability.

异常

至少有一个输入打印票证无效。At least one of the input print tickets is not valid.

basePrintTicketnullThe basePrintTicket is null.

scope 参数不含有效的 PrintTicketScope 值。The scope parameter does not have a valid PrintTicketScope value.

验证、合并和可行性检查操作失败。The validation, merger, and viability checking operation failed.

注解

方法生成可行的打印票证;也就是说,不请求打印机不支持打印功能的票证。The method produces a viable print ticket; that is, a ticket that does not request printing features that the printer does not support. 方法首先根据打印架构验证两个输入打印票证。The method first validates the two input print tickets against the Print Schema. 如果两者都无效,则会引发异常。If either is invalid, an exception is thrown.

然后合并这两个票证。The two tickets are then merged. 如果特定属性的值不同,则生成的合并票证最初使用增量票证的值。If they have different values for a particular property then the resulting merged ticket initially uses the value of the delta ticket.

然后,根据打印机的实际功能检查合并的票证。The merged ticket is then checked against the actual capabilities of the printer. 如果票证中的任何设置与打印机功能不兼容,则打印机驱动程序将使用所需的任何逻辑更改这些设置。If any settings in the ticket are incompatible with the printer's capabilities, then the printer driver changes those settings by using whatever logic it wants. 通常情况下,它会将用户或打印机的默认值替换为设置。Typically, it substitutes the user's or printer's default value for the setting. 驱动程序的替换值源与 basePrintTicket的票证不同,则合并的票证可能具有与这两个输入票证不同的设置。It the driver's source of substitute values is not the same ticket as basePrintTicket, then the merged ticket might have some settings that are different from both of the input tickets. 如果打印机驱动程序必须更改任何设置,则会在 ValidationResultConflictStatus 属性中报告这一事实。If the printer driver has to change any settings then this fact is reported in the ConflictStatus property of the ValidationResult.

若要基于打印队列的默认设置进行合并和验证,应将 basePrintTicket 设置为 DefaultPrintTicketUserPrintTicketTo merge and validate based on a print queue's default settings, you should set basePrintTicket to the DefaultPrintTicket or the UserPrintTicket.

deltaPrintTicket 参数可以是 null,在这种情况下,将对 basePrintTicket 进行验证、检查可行性并返回,并可能会发生更改。The deltaPrintTicket parameter can be null, in which case the basePrintTicket is validated, checked for viability, and returned, possibly with changes.

如果 scope 是作业,则 ValidationResult 中返回的打印票证可以包含带有作业、文档和页前缀的打印架构参数。If the scope is a job, then the print ticket returned in the ValidationResult can include Print Schema parameters with Job, Document, and Page prefixes. 如果 scope 是一个文档,则将忽略 deltaPrintTicket 中的每个作业的设置,并且返回的票证可包含带有文档前缀和页前缀的参数。If the scope is a document, then per-job settings in deltaPrintTicket are ignored, and the returned ticket can include parameters with Document and Page prefixes. 如果 scope 是一个页面,则会忽略每个作业的设置和 deltaPrintTicket 中的每个文档的设置,并且返回的票证可以包含只有页前缀的参数。If the scope is a page, then the per-job settings and the per-document settings in deltaPrintTicket are ignored, and the returned ticket can include parameters with only the Page prefix.

适用于