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:
- Downloading the Sample
- Building the Sample
- Running the Sample
- Additional Information
- Related topics
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.
|Microsoft Windows||Windows 7|
|Windows SDK||Windows 7 Platform Software Development Kit (SDK)|
|Microsoft Visual Studio||Visual Studio 2008 or later|
|Windows SDK||\Program Files\Microsoft SDKs\Windows\v7.0\samples\xps\XpsOMPrint|
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.
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.
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_nameis the name of the printer.
optional_output_filenameis 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
To see all of the XPS programming sample programs, see the XPS Programming Samples on MSDN Code Gallery.
- XPS Print API
- Common XPS Document Programming Tasks