Gets or sets the default printer options associated with this PrintQueue.
Assembly: System.Printing (in System.Printing.dll)
Public Overridable Property DefaultPrintTicket As PrintTicket Get Set
public virtual PrintTicket DefaultPrintTicket { get; set; }
public: virtual property PrintTicket^ DefaultPrintTicket { PrintTicket^ get (); void set (PrintTicket^ value); }
abstract DefaultPrintTicket : PrintTicket with get, set override DefaultPrintTicket : PrintTicket with get, set
Property Value
Type: System.Printing.PrintTicketThe default PrintTicket for the print queue; or null if an error has occurred in the print queue.
The default PrintTicket specifies print job options such as CopyCount, PageOrientation, Duplexing, Stapling, and others.
Each PrintQueue maintains its own DefaultPrintTicket.
In normal operation the DefaultPrintTicket property returns a PrintTicket. If the PrintQueue detects an invalid state, DefaultPrintTicket returns null. If DefaultPrintTicket returns null, the application should display an informational user dialog that an error has occurred on this print queue and that the print job should be restarted with the output directed to a different print queue.
Getting or setting the DefaultPrintTicket property does not validate the PrintTicket. The MergeAndValidatePrintTicket method can be used to validate a PrintTicket.
The following example shows how to use this property while testing a printer's capabilities and configuring 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> 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()
// ---------------------- 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> 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()
.NET Framework
Supported in: 4, 3.5, 3.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Reference
OutputColor property returned in DefaultPrintTicket and UserPrintTicket are not correct in some cases. I have checked with some Ricoh, OKI, HP and Xerox drivers. I've discovered it doesn't matter the brand, it depends on each printer.
The tests were done in a virtual Windows Server 2003 R2 x86 machine.
Does anybody know why?