PrintTicket PrintTicket PrintTicket PrintTicket Class

Definition

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
Inheritance
PrintTicketPrintTicketPrintTicketPrintTicket
Implements

Examples

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

Remarks

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). 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. The element is, in turn, represented by the Stapling property of the PrintTicket object. The PrintTicket document must conform to the Print Schema.

The PrintTicket class enables your application to configure the printer's features without having to engage in any direct writing of XML Stream objects.

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. 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 NOTINBUILD: How to: Extend the Print Schema and Create New Print System Classes.

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. 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.

Caution

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.

If you want to print from a Windows Forms application, see the System.Drawing.Printing namespace.

Constructors

PrintTicket() PrintTicket() PrintTicket() PrintTicket()

Initializes a new instance of the PrintTicket class.

PrintTicket(Stream) PrintTicket(Stream) PrintTicket(Stream) PrintTicket(Stream)

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.

Properties

Collation Collation Collation Collation

Gets or sets a value indicating whether the printer collates its output.

CopyCount CopyCount CopyCount CopyCount

Gets or sets the number of copies for the print job.

DeviceFontSubstitution DeviceFontSubstitution DeviceFontSubstitution DeviceFontSubstitution

Gets or sets a value indicating whether the printer substitutes device-based fonts for computer-based fonts on the print job.

Duplexing Duplexing Duplexing Duplexing

Gets or sets a value indicating what kind of two-sided printing, if any, the printer uses for the print job.

InputBin InputBin InputBin InputBin

Gets or sets a value indicating what input bin (paper tray) to use.

OutputColor OutputColor OutputColor OutputColor

Gets or sets a value indicating how the printer handles content that has color or shades of gray.

OutputQuality OutputQuality OutputQuality OutputQuality

Gets or sets a value indicating the quality of output for the print job.

PageBorderless PageBorderless PageBorderless 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 PageMediaSize PageMediaSize PageMediaSize

Gets or sets the page size for the paper (or other media) that a printer uses for a print job.

PageMediaType PageMediaType PageMediaType PageMediaType

Gets or sets a value indicating what sort of paper or media the printer uses for the print job.

PageOrder PageOrder PageOrder PageOrder

Gets or sets a value indicating whether the printer prints multiple pages back-to-front or front-to-back.

PageOrientation PageOrientation PageOrientation PageOrientation

Gets or sets a value indicating how the page content is oriented for printing.

PageResolution PageResolution PageResolution PageResolution

Gets or sets the level of page resolution that the printer uses for a print job.

PageScalingFactor PageScalingFactor PageScalingFactor PageScalingFactor

Gets or sets the percentage by which the printer enlarges or reduces the print image on a page.

PagesPerSheet PagesPerSheet PagesPerSheet PagesPerSheet

Gets or sets the number of pages that print on each printed side of a sheet of paper.

PagesPerSheetDirection PagesPerSheetDirection PagesPerSheetDirection PagesPerSheetDirection

Gets or sets a value indicating how a printer arranges multiple pages that print on each side of a sheet of paper.

PhotoPrintingIntent PhotoPrintingIntent PhotoPrintingIntent PhotoPrintingIntent

Gets or sets a value indicating in qualitative terms the level of quality the printer uses to print a photograph.

Stapling Stapling Stapling Stapling

Gets or sets a value indicating whether, and where, a printer staples multiple pages.

TrueTypeFontMode TrueTypeFontMode TrueTypeFontMode TrueTypeFontMode

Gets or sets a value indicating how the printer handles text that uses TrueType fonts.

Methods

Clone() Clone() Clone() Clone()

Creates a modifiable clone of this PrintTicket, making deep copies of this object's values.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetXmlStream() GetXmlStream() GetXmlStream() GetXmlStream()

Returns a MemoryStream object that represents the property values of a PrintTicket as an XML stream that conforms to the Print Schema.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
SaveTo(Stream) SaveTo(Stream) SaveTo(Stream) SaveTo(Stream)

Saves the PrintTicket settings to a Stream object by using an XML format that conforms to the Print Schema.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Events

PropertyChanged PropertyChanged PropertyChanged PropertyChanged

Occurs when any property of the PrintTicket changes.

Applies to