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:
Description
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
- Starts a new document in the package.
- Creates a blank-page object.
- Creates a font resource for the glyphs to be added to the page.
- Adds the glyph runs that represent the text to the page by using the font resource created in the previous step.
- Adds the page to the document.
- Closes the package writer to finish the package.
- Closes the print job stream returned by the XPS Print API to indicate to the print spooler that the complete document has been sent.
- Waits for the print spooler to indicate that the print job has completed.
- Checks the completion status and releases all resources.
Requirements
| Product | Version |
| Microsoft Windows | Windows 7 |
| Windows SDK | Windows 7 Platform Software Development Kit (SDK) |
| Microsoft Visual Studio | Visual Studio 2008 or later |
Downloading the Sample
Building the Sample
To build the sample by using Visual Studio:
-
In Windows Explorer navigate to the directory that contains the sample code files.
-
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.
-
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:
- Use the Command Prompt window to navigate to the directory that contains the new executable file.
- 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]
Here,
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.
See Also
- IOpcPartUri
- IXpsOMFontResource
- IXpsOMObjectFactory
- IXpsOMPackageWriter
- IXpsOMPage
- IXpsOMSolidColorBrush
- IXpsOMVisualCollection
- XPS Print API
- XPS_POINT
- XPS_SIZE
- XPS_STYLE_SIMULATION
- Common XPS Document Programming Tasks
- Using the XPS Object Model
Send comments about this topic to Microsoft
Build date: 11/17/2009