Convert LaTeX to XPS Format in Java with Ease

Introduction

Are you looking to seamlessly convert LaTeX documents to XPS format in your Java applications? Aspose.TeX for Java provides a powerful solution, allowing you to achieve this with ease. In this step-by-step guide, we’ll walk you through the process of converting LaTeX to XPS using Aspose.TeX.

Prerequisites

Before diving into the conversion process, make sure you have the following prerequisites in place:

  • Java Development Kit (JDK) installed on your system.
  • Aspose.TeX for Java library downloaded. You can find the download link here.

Import Packages

To get started, import the necessary packages for your Java project. Ensure that you include the Aspose.TeX library in your project dependencies.

package com.aspose.tex.LaTeXXpsConversionSimplest;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;

import com.aspose.tex.InputFileSystemDirectory;
import com.aspose.tex.Interaction;
import com.aspose.tex.OutputFileSystemDirectory;
import com.aspose.tex.TeXConfig;
import com.aspose.tex.TeXJob;
import com.aspose.tex.TeXOptions;
import com.aspose.tex.rendering.XpsDevice;
import com.aspose.tex.rendering.XpsSaveOptions;

import util.Utils;

Now let’s break down the conversion process into multiple steps using the provided code examples.

Step 1: Set Input and Output Directories

options.setInputWorkingDirectory(new InputFileSystemDirectory("Your Input Directory"));
options.setOutputWorkingDirectory(new OutputFileSystemDirectory("Your Output Directory"));

Specify the directories where your LaTeX input file is located and where you want to save the converted XPS file.

Step 2: Configure TeX Options

Configure various options to customize the conversion process according to your needs.

options.setInteraction(Interaction.NonstopMode);
options.setDateTime(new GregorianCalendar(2022, Calendar.DECEMBER, 18).getTime());
options.ignoreMissingPackages(true);
options.noLigatures(true);
options.repeat(true);

Adjust interaction mode, date in the title, handling of missing packages, ligatures, and repetition as needed.

Step 3: Initialize XPS Save Options

options.setSaveOptions(new XpsSaveOptions());

Initialize the options for saving in XPS format.

Step 4: Customize XPS Save Options

options.getSaveOptions().rasterizeFormulas(true);
options.getSaveOptions().rasterizeIncludedGraphics(true);
options.getSaveOptions().subsetFonts(true);

Customize XPS save options to control the conversion of formulas, included graphics, and font subsetting.

Step 5: Run LaTeX to XPS Conversion

new TeXJob("Your Input Directory" + "sample.ltx", new XpsDevice(), options).run();

Initiate the conversion process by running a TeX job with the specified input file, output device (XpsDevice), and options.

Additional Examples

Explore additional conversion methods using different input sources:

Use InputStream

new TeXJob(new ByteArrayInputStream(
    "\\documentclass{article} \\begin{document} Hello, World! \\end{document}".getBytes("ASCII")),
    new XpsDevice(), options).run();

Use Main Input Terminal

new TeXJob(new XpsDevice(), options).run();

Conclusion

With Aspose.TeX for Java, converting LaTeX to XPS is a breeze. Follow these steps, customize the options, and seamlessly integrate this functionality into your Java applications.

FAQ’s

Q1: Can I convert LaTeX documents with complex formulas using Aspose.TeX?

A1: Absolutely! Aspose.TeX handles complex formulas seamlessly during the conversion process.

Q2: Is there a trial version available for Aspose.TeX for Java?

A2: Yes, you can find the free trial version here.

Q3: How can I get support for Aspose.TeX?

A3: Visit the Aspose.TeX forum for assistance and community support.

Q4: Are temporary licenses available for Aspose.TeX?

A4: Yes, you can obtain temporary licenses here.

Q5: Where can I find the documentation for Aspose.TeX?

A5: Refer to the documentation for comprehensive guidance.