PrintTicket 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义打印作业的设置。
public ref class PrintTicket sealed : System::ComponentModel::INotifyPropertyChangedpublic sealed class PrintTicket : System.ComponentModel.INotifyPropertyChangedtype PrintTicket = class
    interface INotifyPropertyChangedPublic NotInheritable Class PrintTicket
Implements INotifyPropertyChanged- 继承
- 
				PrintTicket
- 实现
示例
以下示例演示如何确定特定打印机的功能,以及如何配置打印作业以利用这些功能。
// ---------------------- 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^ printCapabilities = printQueue->GetPrintCapabilities();
   // Modify PrintTicket
   if (printCapabilities->CollationCapability->Contains(Collation::Collated))
   {
      printTicket->Collation = Collation::Collated;
   }
   if (printCapabilities->DuplexingCapability->Contains(Duplexing::TwoSidedLongEdge))
   {
      printTicket->Duplexing = Duplexing::TwoSidedLongEdge;
   }
   if (printCapabilities->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 printCapabilities = printQueue.GetPrintCapabilities();
    // Modify PrintTicket
    if (printCapabilities.CollationCapability.Contains(Collation.Collated))
    {
        printTicket.Collation = Collation.Collated;
    }
    if ( printCapabilities.DuplexingCapability.Contains(
            Duplexing.TwoSidedLongEdge) )
    {
        printTicket.Duplexing = Duplexing.TwoSidedLongEdge;
    }
    if (printCapabilities.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 printCapabilities As PrintCapabilities = printQueue.GetPrintCapabilities()
    ' Modify PrintTicket
    If printCapabilities.CollationCapability.Contains(Collation.Collated) Then
        printTicket.Collation = Collation.Collated
    End If
    If printCapabilities.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge) Then
        printTicket.Duplexing = Duplexing.TwoSidedLongEdge
    End If
    If printCapabilities.StaplingCapability.Contains(Stapling.StapleDualLeft) Then
        printTicket.Stapling = Stapling.StapleDualLeft
    End If
    Return printTicket
End Function ' end:GetPrintTicketFromPrinter()
注解
对象 PrintTicket 是某种类型 XML 文档(称为 PrintTicket 文档)的易用表示形式。 后者是一组说明,指示打印机如何设置其各种功能 (,例如双面打印、整理和装订) 。 例如,若要指示打印机在左上角打开其装订和装订打印作业,文档将具有指定 <JobStapleAllDocuments … >StapleTopLeft 的 元素。 元素又由 Stapling 对象的 属性 PrintTicket 表示。 PrintTicket 文档必须符合 打印架构。
类 PrintTicket 使应用程序能够配置打印机的功能,而无需直接写入 XML Stream 对象。
家庭和企业文件和照片打印机的所有最常用的功能都由 类的属性 PrintTicket 表示。 但是 打印架构 定义了更多不太常见的功能,可以对其进行扩展以处理特殊打印设备的功能。 因此,尽管 PrintTicket 无法继承 和 PrintCapabilities 类,但你可以扩展打印架构以识别 未在 或 PrintCapabilities 类中PrintTicket考虑的打印设备功能。 有关详细信息 ,请参阅如何:扩展打印架构和创建新的打印系统类。
注意PrintTicket使用将 PrintTicket 文档 (作为 Stream) 参数的构造函数创建对象时,整个文档存储在 对象的非公共字段中,包括其中表示不常见的功能的 XML 元素,这些特征不由类的任何公共属性PrintTicket表示。 事实上,如果生成 PrintTicket 文档的驱动程序使用的是 打印架构的专用扩展,则私下定义的标记也会存储为非公共 PrintTicket 文档的一部分。
注意
不支持在 System.Printing Windows 服务或 ASP.NET 应用程序或服务中使用命名空间中的类。 尝试从这些应用程序类型之一中使用这些类可能会产生意外问题,例如服务性能下降和运行时异常。
如果要从 Windows 窗体应用程序打印,请参阅 System.Drawing.Printing 命名空间。
构造函数
| PrintTicket() | 初始化 PrintTicket 类的新实例。 | 
| PrintTicket(Stream) | 使用符合 XML 打印架构的 XML 流(其中包含 PrintTicket 文档)初始化 PrintTicket 类的新实例。 | 
属性
| Collation | 获取或设置一个值,该值表示打印机是否逐份打印其输出。 | 
| CopyCount | 获取或设置打印作业的份数。 | 
| DeviceFontSubstitution | 获取或设置一个值,该值表示打印机是否用基于设备的字体替换打印作业上基于计算机的字体。 | 
| Duplexing | 获取或设置一个值,该值表示打印机在执行打印作业时使用的双面打印类型(如果有)。 | 
| InputBin | 获取或设置一个表示要使用的送纸器(纸盒)的值。 | 
| OutputColor | 获取或设置一个值,该值表示打印机如何处理包含颜色或灰影的内容。 | 
| OutputQuality | 获取或设置一个表示打印作业输出质量的值。 | 
| PageBorderless | 获取或设置一个值,该值表示设备是将内容打印到介质边缘,还是在边缘周围留出一些空白不打印。 | 
| PageMediaSize | 获取或设置打印机在执行打印作业时所用的纸张(或其他介质)的页面大小。 | 
| PageMediaType | 获取或设置一个值,该值表示打印机在执行打印作业时所用的纸张或介质的类型。 | 
| PageOrder | 获取或设置一个值,该值表示打印机是按从后向前还是从前向后的顺序打印多个页面。 | 
| PageOrientation | 获取或设置一个值,该值表示打印时如何定向页面内容。 | 
| PageResolution | 获取或设置打印机在执行打印作业时所使用的页面分辨率等级。 | 
| PageScalingFactor | 获取或设置打印机放大或缩小页面上打印图像的百分率。 | 
| PagesPerSheet | 获取或设置打印在一张纸的每一打印面上的页数。 | 
| PagesPerSheetDirection | 获取或设置一个值,该值表示打印机如何排列打印在一张纸的每一页面上的多页。 | 
| PhotoPrintingIntent | 获取或设置一个值,该值表示打印机在打印照片时所使用的定性的质量级别。 | 
| Stapling | 获取或设置一个表示打印机是否装订多页以及装订多页位置的值。 | 
| TrueTypeFontMode | 获取或设置一个表示打印机如何处理使用 TrueType 字体的文本的值。 | 
方法
| Clone() | 创建此 PrintTicket 的可修改克隆,从而深度复制此对象的值。 | 
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| GetXmlStream() | 返回表示 PrintTicket 属性值的 MemoryStream 对象,作为符合打印架构的 XML 流。 | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| SaveTo(Stream) | 通过使用符合打印架构的 XML 格式将 PrintTicket 设置保存到 Stream 对象。 | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
事件
| PropertyChanged | 在 PrintTicket 的任何属性变化时发生。 |