Partager via


Saving an XPS Document Sample

XpsSave shows how to write an XML Paper Specification (XPS) document to a file 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: "Save - Synchronous" and "Save -Asynchronous". Pressing either button opens a "Save As..." dialog that then initiates writing the XML Paper Specification (XPS) document to a specified file.

"Save - Synchronous" shows the basic operations for writing an XPS document. During synchronous writing the user interface waits until the output completes. Waiting for writing 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 save.

"Save - Asynchronous" allows the user interface to continue while the XPS write operation proceeds independently. Asynchronous saving requires a small amount of additional code set up, but is the recommended "best practice" to maintain a responsive user interface.

This sample demonstrates a specific feature of the Windows Presentation Foundation (WPF) 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

Security - WPF Security

Localization - WPF Globalization and Localization Overview

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

Other Resources

Documents In Windows Presentation Foundation
Document Serialization and Storage
Creating an XPS Document Sample
Printing an XPS Document
Read-Write-Sign an XPS Document Sample
Reading a Package Sample
Writing a Package Sample