LaTeX to XPS | Aspose.TeX for C++
Another target format supported by Aspose.TeX is XPS. An XPS file is actually a ZIP package that contains paginated content of a document, together with the metadata required for proper display by specific viewers (such as Windows XPS Viewer) and printing. All data in a package is represented by files. Some of them are binary and contain resources such as images, fonts, and ICC profiles. Others are XML files in various specific schemas. The latter include files that contain the document data itself. Document data consists of a set of files - each file contains data for an individual page of the document. Such files consist of a single page element and a tree of child elements - Canvas, Path and Glyphs. Canvas is a grouping element that can contain other Canvases, Paths and Glyphs. Its mission is to control the appearance of all child elements as a group. Path elements are used to define vector graphics paths. And Glyphs elements are used to define textual content. All three elements have properties to define various aspects of appearance.
There is the Aspose.Page library that provides an API for manipulating XPS documents, as well as converting them to PDF and raster image formats.
How to convert LaTeX to XPS
The conversion to XPS is just as simple as the conversion to raster image formats, except that in addition to the SaveOptions, we have to change the device to an instance of the XpsDevice class.
1...
2// Initialize the options for saving in Xps format.
3options->set_SaveOptions(System::MakeObject<XpsSaveOptions>());
4
5System::MakeObject<Aspose::TeX::TeXJob>(u"hello-world.ltx", System::MakeObject<XpsDevice>(), options)->Run();
An alternative way to write the main output XPS file
There’s another constructor of the XpsDevice class, which lets us get the resulting XPS file in an alternative way.
1 // Create the stream to write the XPS file to.
2 {
3 System::SharedPtr<System::IO::Stream> xpsStream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::OutputDirectory, u"any-name.xps"), System::IO::FileMode::Create);
4 // Clearing resources under 'using' statement
5 System::Details::DisposeGuard<1> __dispose_guard_0({ xpsStream});
6 // ------------------------------------------
7
8 try
9 {
10 // Create conversion options for Object LaTeX format on Object TeX engine extension.
11 System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::get_ObjectLaTeX());
12 // Specify the file system working directory for the output.
13 options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory));
14 // Initialize the options for saving in XPS format.
15 options->set_SaveOptions(System::MakeObject<XpsSaveOptions>());
16 // Default value.
17 // Run LaTeX to XPS conversion.
18 System::MakeObject<TeXJob>(System::IO::Path::Combine(RunExamples::InputDirectory, u"hello-world.ltx"), System::MakeObject<XpsDevice>(xpsStream), options)->Run();
19 }
20 catch(...)
21 {
22 __dispose_guard_0.SetCurrentException(std::current_exception());
23 }
24 }
The effect is the same as we get here.
You may also check out the free LaTeX-to-XPS conversion web app built based on Aspose.TeX for .NET API. Here is the C++ version page.