Compartir a través de


Document Structure Sample

The Document Structure sample illustrates the difference between an XPS document with and without a structure, and how to add a document structure to an XPS document without one. The sample provides two example XPS documents: "Spec_withoutStructure.xps" and "Spec_withStructure.xps". When viewed in a DocumentViewer control, both files provide exactly the same visual layout, quality, and print output - both documents fully comply with the open XML Paper Specification (XPS). Cut and paste operations for each document, however, is quite different. Build the sample and perform the following steps:

  1. Click File | Open..., select the file "Spec_withoutStructure.xps", and then click OK. Within the "Spec_withoutStructure" document shown in the DocumentViewer control select a part of Table 1-1 and paste it into a blank Word or WordPad document. Notice that an XPS document without structure elements pastes as plain text, not as a formatted table.

  2. Click File | Open... and select "Spec_withStructure.xps". Select a part of Table 1-1 and paste it into the Word or WordPad document. Notice that an XPS document with structure elements uses rich text to paste the selection as styled table elements.

  3. Next click File | Add Structure.... The Add Structure process copies "Spec_withoutStructure.xps" to a new file and then programmatically adds to the new document the two structure elements contained in "FixedPage1_structure.xaml" and "FixedPage2_structure.xaml". The resulting new XPS document is equivalent to "Spec_withStructure.xps".

  4. Click File | Open... and set Files of Type to "All" to select one of the .xaml document structure resource files to view.

The Document Structure sample also contains two subfolders, "Spec_withoutStructure-xps" and "Spec_withStructure-xps". Each of these folders contains the unzipped* version of the "Spec_withoutStructure-xps" and "Spec_withStructure-xps" files.

*Note - To examine the contents of an XPS document, temporarily change the file extension to ".zip" and then open the resulting zip file.

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

  • 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 2005, load the sample solution or project file and then press CTRL+SHIFT+B.

Running the Sample

  • To run the compiled sample from the build environment command window, execute the .exe file in the Bin\Debug or Bin\Release folder contained under the sample source code folder.

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

See Also

Reference

DocumentViewer

Other Resources

Creating an XPS Document Sample
XPS Samples
XML Paper Specification (XPS)