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()

備註

PrintTicket 物件是一種便於使用的標記法,代表某種類型的 XML 檔,稱為「 PrintTicket 檔」。A 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). 例如,若要指示印表機開啟其裝訂,並在左上角裝訂列印工作,檔會有指定StapleTopLeft<JobStapleAllDocuments … > 元素。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. 元素是由 PrintTicket 物件的 Stapling 屬性所表示。The element is, in turn, represented by the Stapling property of the PrintTicket object. PrintTicket 檔必須符合列印架構The PrintTicket document must conform to the Print Schema.

PrintTicket 類別可讓您的應用程式設定印表機的功能,而不需要參與任何直接寫入 XML Stream 物件。The PrintTicket class enables your application to configure the printer's features without having to engage in any direct writing of XML Stream objects.

家用和商務檔案和相片印表機的所有最受歡迎功能,都是以類別 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. 因此,雖然 PrintTicketPrintCapabilities 類別無法被繼承,但是您可以擴充列印架構,以辨識 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)參數來建立 PrintTicket 物件時,整個檔會儲存在物件的非公用欄位中,包括其中的 XML 專案,這表示不是由 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.

警告

在 Windows 服務或 ASP.NET 應用程式或服務內,不支援在 System.Printing 命名空間中使用類別。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 Forms 應用程式進行列印,請參閱 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 PrintTicket列印結構描述的 XML 資料流 (包含 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()

傳回 MemoryStream 物件,以將 PrintTicket 的屬性值表示為符合列印結構描述的 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)

使用符合PrintTicket列印結構描述Stream的 XML 格式,將 設定儲存至 物件。Saves the PrintTicket settings to a Stream object by using an XML format that conforms to the Print Schema.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

事件

PropertyChanged

發生於 PrintTicket 的任何屬性變更時。Occurs when any property of the PrintTicket changes.

適用於