| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Printing Overview |
03/30/2017 |
.net-framework |
|
article |
|
0de8ac41-9aa6-413d-a121-7aa6f41539b1 |
35 |
dotnet-bot |
dotnetcontent |
wpickett |
Printing Overview
With [!INCLUDETLA#tla_winfx], application developers using [!INCLUDETLA#tla_wpf] have a rich new set of printing and print system management [!INCLUDETLA#tla_api#plural]. With [!INCLUDETLA#tla_winvista], some of these print system enhancements are also available to developers creating [!INCLUDETLA#tla_winforms] applications and developers using unmanaged code. At the core of this new functionality is the new [!INCLUDETLA#tla_xps] file format and the [!INCLUDETLA2#tla_xps] print path.
This topic contains the following sections.
About XPS
[!INCLUDETLA2#tla_metro] is an electronic document format, a spool file format and a page description language. It is an open document format that uses [!INCLUDETLA#tla_xml], [!INCLUDETLA#tla_opc], and other industry standards to create cross-platform documents. [!INCLUDETLA2#tla_metro] simplifies the process by which digital documents are created, shared, printed, viewed, and archived. For additional information on [!INCLUDETLA2#tla_metro], see the XPS Web Site.
Several techniques for printing [!INCLUDETLA2#tla_metro] based content using [!INCLUDETLA2#tla_wpf] are demonstrated in Programmatically Print XPS Files. You may find it useful to reference these samples during review of content contained in this topic. (Unmanaged code developers should see documentation for the MXDC_ESCAPE function. [!INCLUDETLA2#tla_winforms#initcap] developers must use the [!INCLUDETLA2#tla_api] in the xref:System.Drawing.Printing namespace which does not support the full [!INCLUDETLA2#tla_xps] print path, but does support a hybrid GDI-to-XPS print path. See Print Path Architecture below.)
XPS Print Path
The [!INCLUDETLA#tla_metro] print path is a new [!INCLUDETLA#tla_mswin] feature that redefines how printing is handled in [!INCLUDETLA2#tla_mswin] applications. Because [!INCLUDETLA2#tla_xps] can replace a document presentation language (such as RTF), a print spooler format (such as WMF), and a page description language (such as PCL or Postscript); the new print path maintains the [!INCLUDETLA2#tla_metro] format from application publication to the final processing in the print driver or device.
The [!INCLUDETLA2#tla_metro] print path is built upon the [!INCLUDETLA2#tla_metro] printer driver model (XPSDrv), which provides several benefits for developers such as [!INCLUDETLA#tla_wys] printing, improved color support, and significantly improved print performance. (For more on XPSDrv, see the Windows Driver Development Kit.)
The operation of the print spooler for [!INCLUDETLA2#tla_metro] documents is essentially the same as in previous versions of [!INCLUDETLA2#tla_mswin]. However, it has been enhanced to support the [!INCLUDETLA2#tla_metro] print path in addition to the existing [!INCLUDETLA2#tla_gdi] print path. The new print path natively consumes an [!INCLUDETLA2#tla_metro] spool file. While user-mode printer drivers written for previous versions of [!INCLUDETLA#tla_mswin] will continue to work, an [!INCLUDETLA2#tla_metro] printer driver (XPSDrv) is required in order to use the [!INCLUDETLA2#tla_metro] print path.
The benefits of the [!INCLUDETLA2#tla_metro] print path are significant, and include:
-
[!INCLUDETLA2#tla_wys] print support
-
Native support of advanced color profiles, which include 32 bits per channel (bpc), CMYK, named-colors, n-inks, and native support of transparency and gradients.
-
Improved print performance for both [!INCLUDETLA2#tla_winfx] and [!INCLUDETLA#tla_win32] based applications.
-
Industry standard [!INCLUDETLA2#tla_metro] format.
For basic print scenarios, a simple and intuitive [!INCLUDETLA2#tla_api] is available with a single entry point for user interface, configuration and job submission. For advanced scenarios, an additional support is added for [!INCLUDETLA#tla_ui] customization (or no [!INCLUDETLA2#tla_ui] at all), synchronous or asynchronous printing, and batch printing capabilities. Both options provide print support in full or partial trust mode.
[!INCLUDETLA2#tla_metro] was designed with extensibility in mind. By using the extensibility framework, features and capabilities can be added to [!INCLUDETLA2#tla_metro] in a modular manner. Extensibility features include:
-
Print Schema. The public schema is updated regularly and enables rapid extension of device capabilities. (See PrintTicket and PrintCapabilities below.)
-
Extensible Filter Pipeline. The [!INCLUDETLA2#tla_metro] printer driver (XPSDrv) filter pipeline was designed to enable both direct and scalable printing of [!INCLUDETLA2#tla_metro] documents. (Lookup "XPSDrv" in the Windows Driver Development Kit.)
Print Path Architecture
While both [!INCLUDETLA2#tla_win32] and [!INCLUDETLA2#tla_winfx] applications support [!INCLUDETLA2#tla_metro], [!INCLUDETLA2#tla_win32] and [!INCLUDETLA2#tla_winforms] applications use a [!INCLUDETLA2#tla_gdi] to [!INCLUDETLA2#tla_metro] conversion in order to create [!INCLUDETLA2#tla_metro] formatted content for the [!INCLUDETLA2#tla_metro] printer driver (XPSDrv). These applications are not required to use the [!INCLUDETLA2#tla_metro] print path, and can continue to use [!INCLUDETLA#tla_emf] based printing. However, most [!INCLUDETLA2#tla_metro] features and enhancements are only available to applications that target the [!INCLUDETLA2#tla_metro] print path.
To enable the use of XPSDrv-based printers by [!INCLUDETLA2#tla_win32] and [!INCLUDETLA2#tla_winforms] applications, the [!INCLUDETLA2#tla_metro] printer driver (XPSDrv) supports conversion of [!INCLUDETLA2#tla_gdi] to [!INCLUDETLA2#tla_metro] format. The XPSDrv model also provides a converter for [!INCLUDETLA2#tla_metro] to [!INCLUDETLA2#tla_gdi] format so that [!INCLUDETLA2#tla_win32] applications can print [!INCLUDETLA2#tla_xps] Documents. For [!INCLUDETLA2#tla_wpf] applications, conversion of [!INCLUDETLA2#tla_metro] to [!INCLUDETLA2#tla_gdi] format is done automatically by the xref:System.Windows.Xps.XpsDocumentWriter.Write%2A and xref:System.Windows.Xps.XpsDocumentWriter.WriteAsync%2A methods of the xref:System.Windows.Xps.XpsDocumentWriter class whenever the target print queue of the write operation does not have an XPSDrv driver. ([!INCLUDETLA2#tla_winforms#initcap] applications cannot print [!INCLUDETLA2#tla_xps] Documents.)
The following illustration depicts the print subsystem and defines the portions provided by [!INCLUDETLA#tla_ms], and the portions defined by software and hardware vendors.
Basic XPS Printing
[!INCLUDETLA2#tla_wpf] defines both a basic and advanced [!INCLUDETLA#tla_api]. For those applications that do not require extensive print customization or access to the complete [!INCLUDETLA2#tla_metro] feature set, basic print support is available. Basic print support is exposed through a print dialog control that requires minimal configuration and features a familiar [!INCLUDETLA2#tla_ui]. Many [!INCLUDETLA2#tla_metro] features are available using this simplified print model.
PrintDialog
The xref:System.Windows.Controls.PrintDialog?displayProperty=nameWithType control provides a single entry point for [!INCLUDETLA2#tla_ui], configuration, and [!INCLUDETLA2#tla_metro] job submission. For information about how to instantiate and use the control, see Invoke a Print Dialog.
Advanced XPS Printing
To access the complete set of [!INCLUDETLA2#tla_metro] features, the advanced print [!INCLUDETLA2#tla_api] must be used. Several relevant [!INCLUDETLA2#tla_api] are described in greater detail below. For a complete list of [!INCLUDETLA2#tla_metro] print path [!INCLUDETLA2#tla_api#plural], see the xref:System.Windows.Xps and xref:System.Printing namespace references.
PrintTicket and PrintCapabilities
The xref:System.Printing.PrintTicket and xref:System.Printing.PrintCapabilities classes are the foundation of the advanced [!INCLUDETLA2#tla_metro] features. Both types of objects are [!INCLUDETLA#tla_xml] formatted structures of print-oriented features such as collation, two-sided printing, stapling, etc. These structures are defined by the print schema. A xref:System.Printing.PrintTicket instructs a printer how to process a print job. The xref:System.Printing.PrintCapabilities class defines the capabilities of a printer. By querying the capabilities of a printer, a xref:System.Printing.PrintTicket can be created that takes full advantage of a printer's supported features. Similarly, unsupported features can be avoided.
The following example demonstrates how to query the xref:System.Printing.PrintCapabilities of a printer and create a xref:System.Printing.PrintTicket using code.
[!code-cppxpscreate#PrinterCapabilities] [!code-csharpxpscreate#PrinterCapabilities] [!code-vbxpscreate#PrinterCapabilities]
PrintServer and PrintQueue
The xref:System.Printing.PrintServer class represents a network print server and the xref:System.Printing.PrintQueue class represents a printer and the output job queue associated with it. Together, these [!INCLUDETLA2#tla_api#plural] allow advanced management of a server's print jobs. A xref:System.Printing.PrintServer, or one of its derived classes, is used to manage a xref:System.Printing.PrintQueue. The xref:System.Printing.PrintQueue.AddJob%2A method is used to insert a new print job into the queue.
The following example demonstrates how to create a xref:System.Printing.LocalPrintServer and access its default xref:System.Printing.PrintQueue by using code.
[!code-csharpxpsprint#PrintQueueSnip] [!code-vbxpsprint#PrintQueueSnip]
XpsDocumentWriter
An xref:System.Windows.Xps.XpsDocumentWriter, with its many the xref:System.Windows.Xps.XpsDocumentWriter.Write%2A and xref:System.Windows.Xps.XpsDocumentWriter.WriteAsync%2A methods, is used to write [!INCLUDETLA2#tla_metro] documents to a xref:System.Printing.PrintQueue. For example, the xref:System.Windows.Xps.XpsDocumentWriter.Write%28System.Windows.Documents.FixedPage%2CSystem.Printing.PrintTicket%29 method is used to output an [!INCLUDETLA2#tla_metro] document and xref:System.Printing.PrintTicket synchronously. The xref:System.Windows.Xps.XpsDocumentWriter.WriteAsync%28System.Windows.Documents.FixedDocument%2CSystem.Printing.PrintTicket%29 method is used to output an [!INCLUDETLA2#tla_metro] document and xref:System.Printing.PrintTicket asynchronously.
The following example demonstrates how to create an xref:System.Windows.Xps.XpsDocumentWriter using code.
[!code-csharpXpsPrint#PrintQueueSnip] [!code-vbXpsPrint#PrintQueueSnip]
The xref:System.Printing.PrintQueue.AddJob%2A methods also provide ways to print. See Programmatically Print XPS Files. for details.
GDI Print Path
While [!INCLUDETLA2#tla_wpf] applications natively support the [!INCLUDETLA2#tla_metro] print path, [!INCLUDETLA2#tla_win32] and [!INCLUDETLA2#tla_winforms] applications can also take advantage of some [!INCLUDETLA2#tla_metro] features. The [!INCLUDETLA2#tla_metro] printer driver (XPSDrv) can convert [!INCLUDETLA2#tla_gdi] based output to [!INCLUDETLA2#tla_metro] format. For advanced scenarios, custom conversion of content is supported using the Microsoft XPS Document Converter (MXDC). Similarly, [!INCLUDETLA2#tla_wpf] applications can also output to the [!INCLUDETLA2#tla_gdi] print path by calling one of the xref:System.Windows.Xps.XpsDocumentWriter.Write%2A or xref:System.Windows.Xps.XpsDocumentWriter.WriteAsync%2A methods of the xref:System.Windows.Xps.XpsDocumentWriter class and designating a non-XpsDrv printer as the target print queue.
For applications that do not require [!INCLUDETLA2#tla_metro] functionality or support, the current [!INCLUDETLA2#tla_gdi] print path remains unchanged.
- For additional reference material on the [!INCLUDETLA2#tla_gdi] print path and the various [!INCLUDETLA2#tla_metro] conversion options, see Microsoft XPS Document Converter (MXDC) and "XPSDrv" in the Windows Driver Development Kit.
XPSDrv Driver Model
The [!INCLUDETLA2#tla_metro] print path improves spooler efficiency by using [!INCLUDETLA2#tla_metro] as the native print spool format when printing to an [!INCLUDETLA2#tla_metro] -enabled printer or driver. The simplified spooling process eliminates the need to generate an intermediate spool file, such as an [!INCLUDETLA2#tla_emf] data file, before the document is spooled. Through smaller spool file sizes, the [!INCLUDETLA2#tla_metro] print path can reduce network traffic and improve print performance.
[!INCLUDETLA2#tla_emf] is a closed format that represents application output as a series of calls into [!INCLUDETLA2#tla_gdi] for rendering services. Unlike [!INCLUDETLA2#tla_emf], the [!INCLUDETLA2#tla_metro] spool format represents the actual document without requiring further interpretation when output to an [!INCLUDETLA2#tla_metro]-based printer driver (XPSDrv). The drivers can operate directly on the data in the format. This capability eliminates the data and color space conversions required when you use [!INCLUDETLA2#tla_emf] files and [!INCLUDETLA2#tla_gdi]-based print drivers.
Spool file sizes are usually reduced when you use [!INCLUDETLA2#tla_metro] Documents that target an [!INCLUDETLA2#tla_metro] printer driver (XPSDrv) compared with their [!INCLUDETLA2#tla_emf] equivalents; however, there are exceptions:
-
A vector graphic that is very complex, multi-layered, or inefficiently written can be larger than a bitmapped version of the same graphic.
-
For screen display purposes, XPS files embed device fonts as well as computer-based fonts; whereas GDI spool files do not embed device fonts. But both kinds of fonts are subsetted (see below) and printer drivers can remove the device fonts before transmitting the file to the printer.
Spool size reduction is performed through several mechanisms:
-
Font subsetting. Only characters used within the actual document are stored in the [!INCLUDETLA2#tla_metro] file.
-
Advanced Graphics Support. Native support for transparency and gradient primitives avoids rasterization of content in the [!INCLUDETLA2#tla_xps] Document.
-
Identification of common resources. Resources that are used multiple times (such as an image that represents a corporate logo) are treated as shared resources and are loaded only once.
-
ZIP compression. All [!INCLUDETLA2#tla_metro] documents use ZIP compression.
See Also
xref:System.Windows.Controls.PrintDialog
xref:System.Windows.Xps.XpsDocumentWriter
xref:System.Windows.Xps.Packaging.XpsDocument
xref:System.Printing.PrintTicket
xref:System.Printing.PrintCapabilities
xref:System.Printing.PrintServer
xref:System.Printing.PrintQueue
How-to Topics
Documents in WPF
XPS
Document Serialization and Storage
Microsoft XPS Document Converter (MXDC)