XpsOMPrint is a sample program that demonstrates how to print an XPS OM by using the XPS Print API.

This topic contains the following sections:


The XpsOMPrint sample program creates a simple XPS document and prints it by using the XPS Print API.

The XPS Print API returns a stream into which the XPS OM can be serialized; hence, in this sample the print job is started and a package writer is created on the stream that is returned by the XPS Print API. The XPS document components are created with a proper sequence of calls to different methods of IXpsOMPackageWriter.

To print an XPS document, XpsOMPrint

  1. Starts a new document in the package.
  2. Creates a blank-page object.
  3. Creates a font resource for the glyphs to be added to the page.
  4. Adds the glyph runs that represent the text to the page by using the font resource created in the previous step.
  5. Adds the page to the document.
  6. Closes the package writer to finish the package.
  7. Closes the print job stream returned by the XPS Print API to indicate to the print spooler that the complete document has been sent.
  8. Waits for the print spooler to indicate that the print job has completed.
  9. Checks the completion status and releases all resources.


Microsoft WindowsWindows 7
Windows SDKWindows 7 Platform Software Development Kit (SDK)
Microsoft Visual StudioVisual Studio 2008 or later


Downloading the Sample

Windows SDK\Program Files\Microsoft SDKs\Windows\v7.0\samples\xps\XpsOMPrint
Code Galleryhttp://go.microsoft.com/fwlink/p/?linkid=155184


Building the Sample

To build the sample by using Visual Studio:

  1. In Windows Explorer navigate to the directory that contains the sample code files.

  2. Double-click the icon for the .sln (solution) file to open the file in Visual Studio.

    Note  The solution file in this sample is compatible with Visual Studio 2008 and later versions of Visual Studio.

  3. In the Build menu, select Build Solution.

The application will be built in the default \Debug or \Release directory.

Running the Sample

To run the sample after it has been built:

  1. Use the Command Prompt window to navigate to the directory that contains the new executable file.
  2. At the command prompt, type the command as described in the Additional Information section.

Additional Information

XpsOMPrint.exe is a console application that creates an XPS document and prints it on the specified printer.

The first parameter in the command is the printer's name. The second parameter, which is optional, specifies the output file. If the output file is not specified, the document will be printed to the device.

The command format is

XpsOMPrint printer_name [optional_output_filename]


printer_name is the name of the printer.

optional_output_filename is the file name of the XPS document to be created. If the output file's name is specified, the document will be printed to that file; otherwise, the document will be printed on the printer specified with printer_name.

To see all of the XPS programming sample programs, see the XPS Programming Samples on MSDN Code Gallery.

Related topics

Common XPS Document Programming Tasks



Community Additions

© 2014 Microsoft