Compartir a través de


Printing an XPS Document

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 - WPF Security

Download sample

Building the Sample

Procedure Title

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

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

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

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

Running the Sample

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

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

See Also

Reference

PrintDialog

Other Resources

How to: Programmatically Print XPS Files
How to: Invoke a Print Dialog
Printing Overview
Printing Samples
Documents in Windows Presentation Foundation
Creating an XPS Document Sample
Saving an XPS Document Sample
Reading a Package Sample
Writing a Package Sample
Microsoft XPS Document Writer