System.Printing
The System.Printing namespace
defines types that provide printing services including managing settings
of print jobs, discovering and selecting print queues, and configuring
printers and print servers. We will explore the most commonly used types
from this namespace.
PrintQueue
PrintQueue represents an
output destination for printing—anytime you print something, you are
sending it to a PrintQueue. The
standard print dialog presents a list of available printers, and each
printer in this list corresponds to a PrintQueue.
You have already seen several examples using PrintQueue—it offers a static CreateXpsDocumentWriter method that can
return an XpsDocumentWriter.
Although this method does not explicitly return a PrintQueue object, the writer it returns is
implicitly bound to the PrintQueue
of the printer the user selected in the print dialog. The examples
shown earlier in this chapter call an overload of CreateXpsDocumentWriter that does not
specify a target PrintQueue,
causing a print dialog to be shown automatically. However, if you have
a PrintQueue object, you can call
one of the overloads that accepts a PrintQueue, in which case no dialog will be
shown, and the document writer will target the specified queue. Example 15-33 shows one way to
do this.
Example 15-33. Creating a document writer with a specific PrintQueue
LocalPrintServer local = new LocalPrintServer( ); PrintQueue pq = local.DefaultPrintQueue; XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq); ...