LaTeX to XPS | Aspose.TeX for Java

Another target format is XPS. An XPS file is physically a ZIP package that contains paginated content of a document, as well as the metadata required for proper display by specific viewers (such as Windows XPS Viewer) and printing. All data in a package is organized as files in directories. Some of them 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 is 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 purpose is control over 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 text content. All three elements have properties to define various aspects of appearence.

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 use an instance of the XpsDevice class.

1// Create conversion options instance.
2...
3// Initialize the options for saving in XPS format.
4options.setSaveOptions(new XpsSaveOptions()); // Default value. Arbitrary assignment.
5// Run LaTeX to XPS conversion.
6new TeXJob(Utils.getInputDirectory() + "sample.ltx", new XpsDevice(), options).run();

An alternative way to write the main output XPS file

There’s another constructor of the XpsDevice class, which allows us to get the resulting XPS file in an alternative way.

 1// Create the stream to write the XPS file to.
 2final OutputStream xpsStream = new FileOutputStream(Utils.getOutputDirectory() + "any-name.xps");
 3{
 4    // Create conversion options for Object LaTeX format upon Object TeX engine extension.
 5    ...
 6    // Initialize the options for saving in XPS format.
 7    options.setSaveOptions(new XpsSaveOptions()); // Default value. Arbitrary assignment.
 8    // Run LaTeX to XPS conversion.
 9    new TeXJob(Utils.getInputDirectory() + "hello-world.ltx", new XpsDevice(xpsStream), options).run();
10} finally {
11  if (xpsStream != null)
12    xpsStream.close();
13}

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 Java version page.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.