XPS and OXPS documents are similar to PDF files and define the layout, appearance, and printing information for a document. There might be scenarios where you might need to convert XPS and OXPS documents to JPG and PNG image formats. To that end, this article will teach you how to convert XPS and OXPS documents to JPG and PNG image format using C++.
- C++ API for Converting XPS, OXPS Files to JPG or PNG Format
- Convert XPS/OXPS Documents to JPG Format
- Convert XPS/OXPS Documents to PNG Format
C++ API for Converting XPS, OXPS Files to JPG or PNG Format
Aspose.Page for C++ is a C++ library for rendering and manipulating XPS and PostScript files. It allows you to create, read and update XPS documents. Furthermore, the API supports converting XPS and OXPS documents to JPG and PNG image formats. You can either install the API through NuGet or download it directly from the downloads section.
PM> Install-Package Aspose.Page.Cpp
Convert XPS/OXPS Documents to JPG Format
The following are the steps to convert XPS and OXPS documents to JPG format.
- Initialize a stream with the source XPS/OXPS file.
- Create an instance of the XpsDocument class using the XPS/OXPS stream.
- Create an instance of the JpegSaveOptions class.
- Specify options like SmoothingMode and Resolution.
- Create an instance of the ImageDevice class.
- Save the XPS/OXPS document to the ImageDevice using XpsDocument->Save(System::SharedPtr<Device> device, System::SharedPtr<SaveOptions> options) method.
- Iterate through the document partitions.
- Initialize the output stream and save the JPG images.
The following sample code shows how to convert XPS/OXPS documents to JPG format using C++.
Convert XPS/OXPS Documents to PNG Format
The following are the steps to convert XPS and OXPS documents to PNG format.
- Initialize a stream with the source XPS/OXPS file.
- Create an instance of the XpsDocument class using the XPS/OXPS stream.
- Create an instance of the PngSaveOptions class.
- Specify options like SmoothingMode and Resolution.
- Create an instance of the ImageDevice class.
- Save the XPS/OXPS document to the ImageDevice using XpsDocument->Save(System::SharedPtr<Device> device, System::SharedPtr<SaveOptions> options) method.
- Iterate through the document partitions.
- Initialize the output stream and save the PNG images.
The following sample code shows how to convert XPS/OXPS documents to PNG format using C++.
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
Conclusion
In this article, you have learned how to convert XPS and OXPS documents to JPG and PNG image formats using C++. Furthermore, Aspose.Page for C++ API provides various additional formats for you to use. You can explore the API in detail by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.