Aspose.TeX's output interface | Python

For formal definitions of I/O implementation, please refer to the API reference of Aspose.TeX for Python.

The idea behind the output directory

Aspose.TeX defines a directory as a mapping between names and bulks of data, where the bulks of data can be files, streams, arrays, or other types of data. The API allows for the specification of separate input and output working directories. For the output, the API provides the general IOutputWorkingDirectory interface, which can be implemented by the user for their specific needs. Additionally, the API provides ready-to-use implementations, which will be discussed below. The IOutputWorkingDirectory interface extends IInputWorkingDirectory, as the engine may first create and write a file, and then read it back. The interface includes the get_output_file() method, which returns the stream to write to, in contrast to the get_file() method, which returns the stream to read from.

Saving the output as a file in the disk file system

As mentioned above, the output_working_directory is commonly set as 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.output_working_directory = OutputFileSystemDirectory(Utils.output_directory)

This particular use case is straightforward, so there is no need to delve into it further.

Saving the output as a ZIP archive file.

Another option is to create a file or stream and use it as a ZIP archive to store the output files. Here is an example:

1# Open the stream for the ZIP archive that will serve as the output working directory.
2with open(path.join(Utils.output_directory, "zip-pdf-out.zip") as out_zip_stream:
3    # Create conversion options instance.
4    ...
5    # Specify a ZIP archive working directory for the output.
6    options.output_working_directory = OutputZipDirectory(out_zip_stream)

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

The idea behind the output terminal

The terminal output is another important aspect of the output. For this, Aspose.TeX for Python defines the general IOutputTerminal interface, which has a single property that returns an instance of the TerminalWriter implementation. The available implementations will be discussed below.

Writing the terminal output to the console

To achieve this, we need to set the terminal_out option as an instance of the OutputConsoleTerminal class.

1# Create conversion options instance.
2...
3# Specify the console as the input terminal.
4options.terminal_out = OutputConsoleTerminal()  # Default value. Arbitrary assignment.

Once again, this is the default value of the option, so there is no real need to specify it. Therefore, this section is provided solely for demonstration purposes.

Writing terminal output to a file

In contrast to the input terminal, Aspose.TeX for Python includes an implementation of the IOutputTerminal interface that enables us to write the terminal output to a file within a specified 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.terminal_out = OutputFileTerminal(options.output_working_directory)

In this case, we instruct the TeX engine to write the terminal output to a file named <job_name>.trm, which will be located in the same output directory as the rest of the output. However, this is not mandatory. We can also provide any other instance of an implementation of IOutputTerminal to the constructor.

Have any questions about Aspose.TeX?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.