PrintTicket 類別

定義

定義列印工作的設定。

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
實作

範例

下列範例示範如何判斷特定印表機的功能,以及如何設定列印工作以利用它們。

// ---------------------- 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 Forms應用程式列印,請參閱 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()

傳回 MemoryStream 物件,以將 PrintTicket 的屬性值表示為符合列印結構描述的 XML 資料流。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
SaveTo(Stream)

使用符合列印結構描述的 XML 格式,將 PrintTicket 設定儲存至 Stream 物件。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

事件

PropertyChanged

發生於 PrintTicket 的任何屬性變更時。

適用於