PrintTicket 类

定义

定义打印作业的设置。Defines the settings of a print job.

public ref class PrintTicket sealed : System::ComponentModel::INotifyPropertyChanged
public sealed class PrintTicket : System.ComponentModel.INotifyPropertyChanged
type PrintTicket = class
    interface INotifyPropertyChanged
Public NotInheritable Class PrintTicket
Implements INotifyPropertyChanged
继承
PrintTicket
实现

示例

下面的示例演示如何确定特定打印机的功能,以及如何配置打印作业以利用这些功能。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 文档(称为PrintTicket 文档)的易于工作的表示形式。 PrintTicketA PrintTicket object is an easy-to-work-with representation of a certain type of XML document called a PrintTicket document. 后者是一组指令,指示打印机如何设置其各种功能(如双面打印、排序和装订)。The latter is a set of instructions telling a printer how to set its various features (such as duplexing, collating, and stapling). 例如,若要指示打印机在左上角打开其装订和装订打印作业,则该文档将具有<JobStapleAllDocuments … >指定StapleTopLeft的元素。For example, to instruct the printer to turn on its stapler and staple print jobs in the upper left corner, the document would have a <JobStapleAllDocuments … > element that specifies StapleTopLeft. 元素依次由Stapling PrintTicket对象的属性表示。The element is, in turn, represented by the Stapling property of the PrintTicket object. PrintTicket 文档必须符合打印架构The PrintTicket document must conform to the Print Schema.

类可让你的应用程序配置打印机的功能,而无需参与任意直接写入 XML Stream对象。 PrintTicketThe PrintTicket class enables your application to configure the printer's features without having to engage in any direct writing of XML Stream objects.

Home 和 business 文件和照片打印机的所有最常用功能都由类的属性PrintTicket表示。All of the most popular features of home and business file and photo printers are represented by properties of PrintTicket the 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. 有关详细信息,请参阅操作说明:扩展打印架构并创建新的打印系统类For more information see How to: Extend the Print Schema and Create New Print System Classes.

注意当使用采用 PrintTicket 文档( Stream作为)参数的构造函数创建对象时,整个文档存储在对象中的非公共字段中,其中包括不太常见的对象中的XML元素PrintTicket不由PrintTicket类的任何公共属性表示的功能。Note When the PrintTicket object is created with the constructor that takes a PrintTicket 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 PrintTicket class. 事实上,如果生成了 PrintTicket 文档的驱动程序使用打印架构的专用扩展,则该私下定义的标记也将作为非公共 PrintTicket 文档的一部分进行存储。In fact, if the driver that produced the PrintTicket document is using a private extension of the Print Schema, that privately defined markup is also stored as part of the non-public PrintTicket 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.

构造函数

PrintTicket()

初始化 PrintTicket 类的新实例。Initializes a new instance of the PrintTicket class.

PrintTicket(Stream)

使用符合 XML 打印架构的 XML 流(其中包含 PrintTicket 文档)初始化 PrintTicket 类的新实例。Initializes a new instance of the PrintTicket class by using an XML stream (that contains a PrintTicket document) that complies with the XML Print Schema.

属性

Collation

获取或设置一个值,该值表示打印机是否逐份打印其输出。Gets or sets a value indicating whether the printer collates its output.

CopyCount

获取或设置打印作业的份数。Gets or sets the number of copies for the print job.

DeviceFontSubstitution

获取或设置一个值,该值表示打印机是否用基于设备的字体替换打印作业上基于计算机的字体。Gets or sets a value indicating whether the printer substitutes device-based fonts for computer-based fonts on the print job.

Duplexing

获取或设置一个值,该值表示打印机在执行打印作业时使用的双面打印类型(如果有)。Gets or sets a value indicating what kind of two-sided printing, if any, the printer uses for the print job.

InputBin

获取或设置一个表示要使用的送纸器(纸盒)的值。Gets or sets a value indicating what input bin (paper tray) to use.

OutputColor

获取或设置一个值,该值表示打印机如何处理包含颜色或灰影的内容。Gets or sets a value indicating how the printer handles content that has color or shades of gray.

OutputQuality

获取或设置一个表示打印作业输出质量的值。Gets or sets a value indicating the quality of output for the print job.

PageBorderless

获取或设置一个值,该值表示设备是将内容打印到介质边缘,还是在边缘周围留出一些空白不打印。Gets or sets a value indicating whether the device prints content to the edge of the media or leaves an unprinted margin around the edge.

PageMediaSize

获取或设置打印机在执行打印作业时所用的纸张(或其他介质)的页面大小。Gets or sets the page size for the paper (or other media) that a printer uses for a print job.

PageMediaType

获取或设置一个值,该值表示打印机在执行打印作业时所用的纸张或介质的类型。Gets or sets a value indicating what sort of paper or media the printer uses for the print job.

PageOrder

获取或设置一个值,该值表示打印机是按从后向前还是从前向后的顺序打印多个页面。Gets or sets a value indicating whether the printer prints multiple pages back-to-front or front-to-back.

PageOrientation

获取或设置一个值,该值表示打印时如何定向页面内容。Gets or sets a value indicating how the page content is oriented for printing.

PageResolution

获取或设置打印机在执行打印作业时所使用的页面分辨率等级。Gets or sets the level of page resolution that the printer uses for a print job.

PageScalingFactor

获取或设置打印机放大或缩小页面上打印图像的百分率。Gets or sets the percentage by which the printer enlarges or reduces the print image on a page.

PagesPerSheet

获取或设置打印在一张纸的每一打印面上的页数。Gets or sets the number of pages that print on each printed side of a sheet of paper.

PagesPerSheetDirection

获取或设置一个值,该值表示打印机如何排列打印在一张纸的每一页面上的多页。Gets or sets a value indicating how a printer arranges multiple pages that print on each side of a sheet of paper.

PhotoPrintingIntent

获取或设置一个值,该值表示打印机在打印照片时所使用的定性的质量级别。Gets or sets a value indicating in qualitative terms the level of quality the printer uses to print a photograph.

Stapling

获取或设置一个表示打印机是否装订多页以及装订多页位置的值。Gets or sets a value indicating whether, and where, a printer staples multiple pages.

TrueTypeFontMode

获取或设置一个表示打印机如何处理使用 TrueType 字体的文本的值。Gets or sets a value indicating how the printer handles text that uses TrueType fonts.

方法

Clone()

创建此 PrintTicket 的可修改克隆,从而深度复制此对象的值。Creates a modifiable clone of this PrintTicket, making deep copies of this object's values.

Equals(Object)

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

(继承自 Object)
GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
GetXmlStream()

返回表示 PrintTicket 属性值的 MemoryStream 对象,作为符合打印架构的 XML 流。Returns a MemoryStream object that represents the property values of a PrintTicket as an XML stream that conforms to the Print Schema.

MemberwiseClone()

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

(继承自 Object)
SaveTo(Stream)

通过使用符合打印架构的 XML 格式将 PrintTicket 设置保存到 Stream 对象。Saves the PrintTicket settings to a Stream object by using an XML format that conforms to the Print Schema.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

事件

PropertyChanged

PrintTicket 的任何属性变化时发生。Occurs when any property of the PrintTicket changes.

适用于