Aspose.TeX's output interface | Java

Please, refer to Aspose.TeX for Java API reference for formal definitions of I/O implementation.

The concept of the output directory

Since I/O primitives of the TeX language can only deal with file names, Aspose.TeX defines a directory as a mapping between names and bulks of data. The bulks of data are supposed to be files, streams, arrays, or whatever else.The API allows us to specify the input and output working directories separately. It provides the general IOutputWorkingDirectory interface for the output, which the user can implement for their own purposes. It also provides its own implementations, which will be discussed below. The interface extends IInputWorkingDirectory, since the engine may first create and write a file, and then read it back. The interface’s own method getOuputFile() returns the stream to write to, as opposed to the stream to read returned by getFile().

Writing file output to the disk file system

As we mentioned above, the most common value for the OutputWorkingDirectory would likely be an instance of the OutputFileSystemDirectory class.

Here’s how we would set it:

1// Create conversion options instance.
2...
3// Specify a file system working directory for the output.
4options.setOutputWorkingDirectory(new OutputFileSystemDirectory(Utils.getOutputDirectory()));

This use case is quite simple, so we won’t dwell on it for a long time.

Writing file output to a ZIP archive

We can also create a file (or stream) and let the TeX engine use it as a ZIP archive to store the output files. Here it is:

 1// Open the stream for the ZIP archive that will serve as the output working directory.
 2final OutputStream outZipStream = new FileOutputStream(Utils.getOutputDirectory() + "zip-pdf-out.zip");
 3{
 4    // Create conversion options instance.
 5    ...
 6    // Specify a ZIP archive working directory for the output.
 7    options.setOutputWorkingDirectory(new OutputZipDirectory(outZipStream));
 8} finally {
 9    if (outZipStream != null)
10        outZipStream.close();
11}

First, we create an output stream for the ZIP file. Then, after creating the conversion options, we set the OutputWorkingDirectory option to be an instance of the OutputZipDirectory class.

The concept of the output terminal

There’s another important part of the output — the terminal output. As for this one, Aspose.TeX for Java defines the general IOutputTerminal interface as having two methods. One of them returns a BufferedWriter instance. Another one returns an OutputStream instance as the underlying stream. Provided implementations of the interface are discussed below.

Writing terminal output to the console

To do this, we need to set the TerminalOut option to be an instance of the OutputConsoleTerminal class.

1// Create conversion options instance.
2...
3// Specify the console as the input terminal.
4options.setTerminalOut(new OutputConsoleTerminal()); // Default value. Arbitrary assignment.

Again, this is the default value of the option, so there’s no real need to specify it. Due to this, this section serves only demonstration purposes.

Writing terminal output to a file

Unlike the input terminal, Aspose.TeX for Java provides an implementation of the IOutputTerminal, which allows us to write the terminal output to a file in some output directory.

1// Create conversion options instance.
2...
3// Specify that the terminal output must be written to a file in the output working directory.
4// The file name is <job_name>.trm.
5options.setTerminalOut(new OutputFileTerminal(options.getOutputWorkingDirectory()));

Here we ask the TeX engine to write the terminal output to the file with the name <job_name>.trm, which will be stored in the same output directory that we specified for the rest of the output. But this is not necessary. We might as well pass any other instance of any implementation of IOutputTerminal to the constructor.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.