Write output to ZIP

Save the result of a TeX file conversion into ZIP via C# .NET

 

TeX is a programming language used to write programs for a computer document preparation system which is also called TeX (the TeX engine). Their main purpose is to help in writing mathematical or technical papers. Anyway, in short, the main purpose of TeX is to help with the creation of mathematical or technical text writing. But when the file is already created and you do not want any further manipulations on it, you may want to convert it to another, more popular, format.

The Aspose.TeX API solution, among other features, allows conversion of TeX files and then saving the result into a ZIP archive. Here you will find a code snippet on how to convert TeX to PDF and save the output into ZIP. The conversion API is capable of transforming TeX using any language supported by .NET. The API you see here can also be used to create your own cross-platform application or be integrated into your .NET project. Such cross-platform converters are also present in the Aspose ecosystem. But to run the examples we need:

  • The Aspose.TeX for .NET API which is a feature-rich, powerful, and easy-to-use document manipulation and conversion API for C# platform.

  • Open the NuGet package manager, search for Aspose.TeX, and install it. You may also use the following command from the Package Manager Console:

Package Manager Console Command

PM> Install-Package Aspose.TeX

Steps to use ZIP directories for output when converting a TeX file C#.

  1. Create an instance of the TeXOptions class.
  2. Specify a ZIP archive working directory for the output using the OutputWorkingDirectory property.
  3. Specify the console as the output terminal using the OutputConsoleTerminal class.
  4. Define the save options using the PdfSaveOptions class.
  5. Create an object of the TeXJob class with a newly created PdfDevice and run conversion using the Run() method.
  6. Finalize the output ZIP archive by calling the OutputZipDirectory ’s method Finish().

C# code example: Using ZIP directories for output

using Aspose.TeX.IO;
using Aspose.TeX.Presentation.Pdf;
using System.IO;
// Create the TeX engine options for no format upon ObjectTeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectIniTeX);

// Open the stream on the ZIP archive that will serve as the output working directory.
using (Stream outZipStream = File.Open(Path.Combine(RunExamples.OutputDirectory, "zip-pdf-out.zip"), FileMode.Create))
{
    // Create conversion options for default ObjectTeX format upon ObjectTeX engine extension.
    TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX());
    // Specify a ZIP archive working directory for the output.
    options.OutputWorkingDirectory = new OutputZipDirectory(outZipStream);
    // Specify the console as the output terminal.
    options.TerminalOut = new OutputConsoleTerminal(); // Default value. Arbitrary assignment.

    // Define the saving options.
    options.SaveOptions = new PdfSaveOptions();
    // Run the job.
    TeXJob job = new TeXJob("hello-world", new PdfDevice(), options);
    job.Run();

    // Finalize output ZIP archive.
    ((OutputZipDirectory)options.OutputWorkingDirectory).Finish();
}



FAQ

1. How do I view TeX output?

To open a TeX file so that the result of typesetting could be viewed, use the cross-platform TeX Viewer . It also allows you save the file as images.

2. Can I write TeX output to a ZIP archive?

Yes, this API Solution provides such functionality. You will need the OutputZipDirectory class, which implements a method for getting a file stream to write to when the working directory is a ZIP archive.

3. How to write TeX output to a ZIP archive?

Create an instance of the TeXOptions class. Then specify a ZIP archive working directory for the output. Specify saving options and run the conversion. Finally, finalize writing the output to a ZIP archive by calling the Finish() method.

TeX What is TeX File Format

TeX is not actually a format. It is both a programming language and also an interpreter engine that understands this language. A TeX file is a plain text file created using TeX syntax to be converted to some target format by being processed by a TeX engine. This output document may include graphics, tables, lists, formulas, and equations.