XPS to PNG
Convert XPS to PNG via API Solution for C++.
Aspose.Page for XPS to PNG converter offers conversion to PNG image with using of any language supported by C++.
The API you see here can be used to create your own cross-platform application or be integrated into your C++ project.
In order to convert XPS to PNG:
Aspose.Page for C++ API which is a feature-rich, powerful and easy to use document manipulation and conversion API for C++ platform.
You can download its latest version directly, just open NuGet package manager, and search for Aspose.Page.Cpp and install. You may also use the following command from the Package Manager Console.
Package Manager Console Command
PM> Install-Package Aspose.Page.Cpp
Steps to Convert XPS to PNG using C++
Aspose.Page makes it easy for the developers to load and convert XPS files to PNG in just a few lines of code.
- Create instance of XpsDocument Class with input file name and XpsLoadOptions as constructor parameters.
- Define save options as instance of PngSaveOptions .
- Call SaveAsImage method of XPS document to save each document page to an array bytes of image.
- Process errors if needs.
XPS to PNG C++ Conversion
// The path to the documents directory. | |
System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion(); | |
//Outut file | |
System::String outputFileName = dataDir + u"XPStoImage_out.png"; | |
// Load XPS document form the XPS file | |
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(dataDir + u"input.xps", System::MakeObject<XpsLoadOptions>()); | |
// Initialize options object with necessary parameters. | |
System::SharedPtr<PngSaveOptions> options = System::MakeObject<PngSaveOptions>(); | |
options->set_SmoothingMode(System::Drawing::Drawing2D::SmoothingMode::HighQuality); | |
options->set_Resolution(300); | |
options->set_PageNumbers(System::MakeArray<int32_t>({1, 2, 6})); | |
// Save XPS document to the images byte arrays. The first dimension is for inner documents | |
// and the second one is for pages within inner documents. | |
System::ArrayPtr<System::ArrayPtr<System::ArrayPtr<uint8_t>>> imagesBytes = document->SaveAsImage(options); | |
// Iterate through document partitions (fixed documents, in XPS terms) | |
for (int32_t i = 0; i < imagesBytes->get_Length(); i++) | |
{ | |
// Iterate through partition pages | |
for (int32_t j = 0; j < imagesBytes[i]->get_Length(); j++) | |
{ | |
// Initialize image output stream | |
{ | |
System::SharedPtr<System::IO::Stream> imageStream = System::IO::File::Open(System::IO::Path::GetDirectoryName(outputFileName) + System::IO::Path::DirectorySeparatorChar + System::IO::Path::GetFileNameWithoutExtension(outputFileName) + u"_" + (i + 1) + u"_" + (j + 1) + System::IO::Path::GetExtension(outputFileName), System::IO::FileMode::Create, System::IO::FileAccess::Write); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ imageStream}); | |
// ------------------------------------------ | |
try | |
{ | |
imageStream->Write(imagesBytes[i][j], 0, imagesBytes[i][j]->get_Length()); | |
} | |
catch(...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
} | |
} | |
XPS to PNG Conversion Web Application
XPS What is XPS File Format
XPS format is similar to PDF format. Both are page description language (PDL) formats. EPS is based on HTML and not on PostScript language. The .eps file is capable to contain a markup of the document's structure along with the information on how the document would look like. There are also added instructions on how to print and render the document. The feature of the format is that it fixes the document's description which means that it will look the same no matter who and from what operational system opens it.
PNG What is PNG File Format
Portable Network Graphics or PNG is one of the most popular image formats. It gives you really good compression maintaining the high level of quality of the picture. PNG is also one of the best formats for web projects, as the files are lighter and images are easy to scale. One drawback of the format when used on the web is that it is not possible to add keywords to the image directly.