Printing an XPS Document

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

XpsPrint shows how to print an XML Paper Specification (XPS) document either synchronously or asynchronously. When executed, the sample displays a "Select Content" ComboBox that allows the user to choose one of five predefined content types: a single visual, multiple visuals, a flow document, a single fixed document, or multiple fixed documents. The selected content is displayed in DocumentViewer control located in the right pane of the application window. After the content is selected, two print buttons are enabled: "Print - Synchronous" and "Print -Asynchronous". Pressing either button opens a printer dialog which then initiates print output of the XML Paper Specification (XPS) document to the selected printer.   

"Print - Synchronous" shows the basic operations for printing an XML Paper Specification (XPS) document. During synchronous printing the user interface waits until the print output completes. Waiting for printing to complete might be satisfactory for small documents where the output time is quick, but is generally not recommended since large documents might take a relatively significant amount of time to print.

"Print - Asynchronous" allows the user interface to continue while the print output proceeds independently. Asynchronous printing requires a small amount of additional code set up, but is the recommended "best practice" for maintaining a responsive user interface.

This sample demonstrates a specific feature of the Windows Presentation Foundation and, consequently, does not follow application development best practices. For comprehensive coverage of Windows Presentation Foundation (WPF) and Microsoft .NET Framework application development best practices, refer to the following as appropriate:

Accessibility - Accessibility Best Practices

Localization - WPF Globalization and Localization Overview

Performance - Optimizing WPF Application Performance

Security - Windows Presentation Foundation Security

  • Install the Windows Software Development Kit (SDK) and open its build environment command window. On the Start menu, point to All Programs, Microsoft Windows SDK, and then click CMD Shell.

  • Download the sample, usually from the software development kit (SDK) documentation, to your hard disk drive.

  • To build the sample from the build environment command window, go to the source directory of the sample. At the command prompt, type MSBUILD.

  • To build the sample in Microsoft Visual Studio, load the sample solution or project file and then press CTRL+SHIFT+B.

  • To run the compiled sample with debugging in Visual Studio, press F5.

  • To run the sample from a CMD Shell command window, execute the .exe file located in the source folder of the sample.