Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/58d1c43acd187f1cde7917fa9a430281 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/58d1c43acd187f1cde7917fa9a430281 to your computer and use it in GitHub Desktop.
Convert LaTeX to PNG, JPEG, TIFF, BMP, SVG with .NET

Aspose.TeX for .NET – Convert LaTeX to Image Examples

These snippets demonstrate converting LaTeX documents to various image formats with Aspose.TeX for .NET. Convert LaTeX to PNG, JPEG, TIFF, BMP, or SVG with flexible configuration options for professional typesetting and document processing.

Key Use Cases

  • Convert LaTeX to PNG image
  • How to convert LaTeX to PNG with custom resolution
  • How to convert LaTeX to PNG with manual page-by-page saving
  • Convert LaTeX to JPEG
  • Convert LaTeX to TIFF
  • Convert LaTeX to BMP
  • Convert LaTeX to SVG (vector graphics)

How to Run Examples

  1. Reference Aspose.TeX for .NET: Aspose.TeX on Windows; Aspose.TeX.Drawing on non‑Windows.
  2. Copy a snippet into your project.
  3. Apply a temporary license as described in the licensing guide.
  4. Build and run.

Restrictions

In evaluation mode, the output may contain watermarks and limitations. Apply a valid license to unlock full features.

Related Documentation

More about LaTeX conversion to image formats:

Related Resources

Requirements

  • .NET 6.0+, .NET Core, or .NET Framework
  • Aspose.TeX for .NET library
Aspose.TeX for .NET – Convert LaTeX to Image Examples
// Convert LaTeX to BMP
// Learn more: https://docs.aspose.com/tex/net/latex-to-image/
// Create conversion options for Object LaTeX format upon Object TeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Initialize the options for saving in BMP format.
options.SaveOptions = new BmpSaveOptions();
// Run LaTeX to BMP conversion.
new TeXJob(Path.Combine(DataDir, "hello-world.ltx"), new ImageDevice(), options).Run();
// Convert LaTeX to JPEG
// Learn more: https://docs.aspose.com/tex/net/latex-to-image/
// Create conversion options for Object LaTeX format upon Object TeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Initialize the options for saving in JPEG format.
options.SaveOptions = new JpegSaveOptions();
// Run LaTeX to JPEG conversion.
new TeXJob(Path.Combine(DataDir, "hello-world.ltx"), new ImageDevice(), options).Run();
// Convert LaTeX to PNG - alternative approach with manual page-by-page saving
// Learn more: https://docs.aspose.com/tex/net/latex-to-image/
// Create conversion options for Object LaTeX format upon Object TeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Initialize the options for saving in PNG format.
PngSaveOptions pngSaveOptions = new PngSaveOptions();
// Disable automatic image writing - we'll write them manually.
pngSaveOptions.DeviceWritesImages = false;
options.SaveOptions = pngSaveOptions;
// Create the image device.
ImageDevice device = new ImageDevice();
// Run LaTeX to PNG conversion.
new TeXJob(Path.Combine(DataDir, "hello-world.ltx"), device, options).Run();
// Save pages file by file (useful for multi-page documents).
for (int i = 0; i < device.Result.Length; i++)
{
using (Stream fs = File.Open(Path.Combine(OutputDir, $"page-{i + 1}.png"), FileMode.Create))
fs.Write(device.Result[i], 0, device.Result[i].Length);
}
// Convert LaTeX to PNG - simplest approach
// Learn more: https://docs.aspose.com/tex/net/latex-to-image/
// Create conversion options for Object LaTeX format upon Object TeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Initialize the options for saving in PNG format.
PngSaveOptions pngOptions = new PngSaveOptions();
// Set image resolution to 300 DPI.
pngOptions.Resolution = 300;
options.SaveOptions = pngOptions;
// Run LaTeX to PNG conversion.
new TeXJob(Path.Combine(DataDir, "hello-world.ltx"), new ImageDevice(), options).Run();
// Convert LaTeX to SVG - alternative approach with custom device
// Learn more: https://docs.aspose.com/tex/net/latex-to-image/
// Create conversion options for Object LaTeX format upon Object TeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
options.InputWorkingDirectory = new InputFileSystemDirectory(DataDir);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Initialize the options for saving in SVG format.
options.SaveOptions = new SvgSaveOptions();
// Run LaTeX to SVG conversion.
new TeXJob("hello-world.ltx", new SvgDevice(), options).Run();
// Convert LaTeX to SVG - simplest approach
// Learn more: https://docs.aspose.com/tex/net/latex-to-image/
// Create conversion options for Object LaTeX format upon Object TeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Initialize the options for saving in SVG format.
options.SaveOptions = new SvgSaveOptions();
// Run LaTeX to SVG conversion.
new TeXJob(Path.Combine(DataDir, "hello-world.ltx"), new SvgDevice(), options).Run();
// Convert LaTeX to TIFF
// Learn more: https://docs.aspose.com/tex/net/latex-to-image/
// Create conversion options for Object LaTeX format upon Object TeX engine extension.
TeXOptions options = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectLaTeX);
// Specify a file system working directory for the output.
options.OutputWorkingDirectory = new OutputFileSystemDirectory(OutputDir);
// Initialize the options for saving in TIFF format.
options.SaveOptions = new TiffSaveOptions();
// Run LaTeX to TIFF conversion.
new TeXJob(Path.Combine(DataDir, "hello-world.ltx"), new ImageDevice(), options).Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment