LaTeX to XPS | Aspose.TeX for .NET

Another target format is XPS. An XPS file is physically a ZIP package that contains paginated content of a document, along 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. It serves 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 LaTeX to XPS conversion is just as simple as the conversion to raster image formats, except that the SaveOptions MUST be set to an XpsSaveOptions class instance (by default or explicitly), and the device MUST be changed to an instance of the XpsDevice class.

1// Create conversion options instance.
2...
3// Initialize the options for saving in XPS format.
4options.SaveOptions = new XpsSaveOptions(); // Default value. Arbitrary assignment.
5// Run LaTeX to XPS conversion.
6new TeXJob(Path.Combine(RunExamples.InputDirectory, "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 lets us get the resulting XPS file in an alternative way.

 1// Create the stream to write the XPS file to.
 2using (Stream xpsStream = File.Open(Path.Combine(RunExamples.OutputDirectory, "any-name.xps"), FileMode.Create))
 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.SaveOptions = new XpsSaveOptions(); // Default value. Arbitrary assignment.
 8    // Run LaTeX to XPS conversion.
 9    new TeXJob(Path.Combine(RunExamples.InputDirectory, "hello-world.ltx"), new XpsDevice(xpsStream), options).Run();
10}

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.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.