XPS and OXPS documents define the layout, appearance, and printing information. These documents are similar to PDF files. Due to the high popularity of the PDF format, you might find yourself in situations where you need to convert XPS and OXPS documents to PDF format. To that end, this article will teach you how to convert XPS and OXPS documents to PDF format using C++.
- C++ API for Converting XPS and OXPS Documents to PDF Format
- Convert XPS/OXPS Documents to PDF Format
- Convert Selected Pages of XPS/OXPS Documents to PDF Format
C++ API for Converting XPS and OXPS Documents to PDF 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 PDF format. 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 PDF Format
The following are the steps to convert XPS and OXPS documents to PDF format.
- Initialize a stream with the output PDF file.
- 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 PdfSaveOptions class.
- Specify options like JpegQualityLevel and ImageCompression.
- Save the output PDF file using the XpsDocument->Save(System::SharedPtr<Device> device, System::SharedPtr<SaveOptions> options) method.
The following sample code shows how to convert XPS/OXPS documents to PDF format using C++.
Convert Selected Pages of XPS/OXPS Documents to PDF Format
While converting XPS and OXPS files to PDF format, you can also specify the pages you want to convert. The output PDF file will contain only the pages you select. To achieve this, please follow the steps given below.
- Initialize a stream with the output PDF file.
- 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 PdfSaveOptions class.
- Specify options like JpegQualityLevel and ImageCompression.
- Specify the pages that you want to convert using the PdfSaveOptions->set_PageNumbers(System::ArrayPtr<int32_t> value) method.
- Save the output PDF file using the XpsDocument->Save(System::SharedPtr<Device> device, System::SharedPtr<SaveOptions> options) method.
The following sample code demonstrates how to convert selected pages of XPS and OXPS documents to PDF format using C++.
Get a Free Licence
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 PDF format using C++. Additionally, you have seen how to convert selected pages of the XPS/OXPS documents to PDF format using Aspose.Page for C++ API. The API provides many additional features for working with XPS documents that you can explore in detail by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.