PrintTicket Construtores
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da PrintTicket classe.
Sobrecargas
| Name | Descrição |
|---|---|
| PrintTicket() |
Inicializa uma nova instância da PrintTicket classe. |
| PrintTicket(Stream) |
Inicializa uma nova instância da PrintTicket classe usando um fluxo XML (que contém um documento PrintTicket) que cumpre o XML Print Schema. |
PrintTicket()
Inicializa uma nova instância da PrintTicket classe.
public:
PrintTicket();
public PrintTicket();
Public Sub New ()
Exemplos
O exemplo seguinte mostra como usar este construtor ao fundir dois bilhetes de impressão.
/// <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
Aplica-se a
PrintTicket(Stream)
Inicializa uma nova instância da PrintTicket classe usando um fluxo XML (que contém um documento PrintTicket) que cumpre o XML Print Schema.
public:
PrintTicket(System::IO::Stream ^ xmlStream);
public PrintTicket(System.IO.Stream xmlStream);
new System.Printing.PrintTicket : System.IO.Stream -> System.Printing.PrintTicket
Public Sub New (xmlStream As Stream)
Parâmetros
- xmlStream
- Stream
Um fluxo XML que descreve um trabalho de impressão e está em conformidade com o Esquema de Impressão.
Exceções
xmlStream é null.
xmlStream não é XML válido.
Observações
O construtor não repõe a posição de leitura-escrita do fluxo de volta à sua posição original. Assim, deve reiniciá-lo imediatamente após chamar o construtor.
Todo o documento PrintTicket é armazenado num campo não público no objeto, incluindo os elementos XML que expressam características menos comuns e que não são representadas por nenhuma das propriedades públicas da PrintTicket classe. De facto, se o driver que produziu o documento PrintTicket estiver a usar uma extensão privada do Print Schema, essa marcação definida privadamente também é armazenada como parte do documento não público do PrintTicket.
As partes privadas do documento, se existirem, não são validadas pelo construtor, mas todas as partes definidas pelo Esquema de Impressão são validadas, incluindo as partes que não são representadas por nenhuma das propriedades públicas da PrintTicket classe. Assim, o FormatException pode ser descartado mesmo que toda a marcação XML correspondente às propriedades públicas seja válida.
Quando qualquer uma das propriedades do PrintTicket é escrita, este documento PrintTicket não público também é alterado.
É este documento PrintTicket não público que é devolvido pelos GetXmlStream métodos e SaveTo .