Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active January 10, 2025 13:57
Convert LaTeX to PNG in Python. For more details: https://kb.aspose.com/tex/python/convert-latex-to-png-in-python/
import aspose.tex as tex
import os
from aspose.tex import *
from aspose.tex.io import *
from aspose.tex.presentation.image import *
path = "C://"
# Create the stream
with open(os.path.join(path, "any-name.png"), "wb") as png_stream:
# Create conversion options
options = TeXOptions.console_app_options(TeXConfig.object_latex)
# Specify the directory
options.output_working_directory = OutputFileSystemDirectory(path)
# Create PngSaveOptions object
options.save_options = PngSaveOptions()
# Save output PNG
TeXJob(os.path.join(path, "hello-world.ltx"), ImageDevice(True), options).run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment