この簡単なトピックでは、Javaを使用してLaTeXをPNGにレンダリングする方法について詳しく説明します。また、LaTeXファイルは.texファイルとして認識されており、単純なAPIメソッドとプロパティを使用してJavaを使用してLaTeXをPNGに簡単に変換できます。 API呼び出しは、他のサードパーティのツールやアプリケーションソフトウェアに依存しないため、コードはLinux、macOS、またはMSWindowsプラットフォームのJava環境で実行できます。
Javaを使用してLaTeXをPNGにレンダリングする手順
- MavenリポジトリからAspose.TeXJARファイル参照を追加してプロジェクトを構成します
- TeXOptionsを使用してLaTeX形式のファイルを変換するためのオプションを作成します
- LaTeXをPNG画像形式で保存するためにPngSaveOptionsを初期化します
- TexJobクラスを使用してLaTeXからPNGへの画像レンダリングを実行します
LaTeXドキュメントにはプレーンテキストが含まれており、技術ユーザー向けの科学および研究作業に使用されます。 * LaTeXをJavaで画像に変換するために、最初にTeXOptionsクラスオブジェクトを作成して入力ファイルをロードします。次に、次の手順に進み、 PngSaveOptions *オブジェクトを初期化して、入力ファイルをPNG形式の画像にレンダリングします。この2段階のレンダリング手順は、Javaを使用したいくつかの簡単なAPI呼び出しで完了します。
Javaを使用してLaTeXをPNGに変換するコード
package texexamples; | |
import com.aspose.tex.License; | |
import com.aspose.tex.OutputFileSystemDirectory; | |
import com.aspose.tex.TeXConfig; | |
import com.aspose.tex.TeXJob; | |
import com.aspose.tex.TeXOptions; | |
import com.aspose.tex.rendering.ImageDevice; | |
import com.aspose.tex.rendering.PngSaveOptions; | |
public class TexExamples { | |
public static void main(String[] LatexArgs) throws Exception { // main method for converting LaTeX file to PNG image in Java | |
// Set Aspose.TeX license before converting LaTeX file to PNG in Java | |
License TeXLicense = new License(); | |
TeXLicense.setLicense("Aspose.TeX.lic"); | |
// Create options for converting LaTeX format file | |
TeXOptions options = TeXOptions.consoleAppOptions(TeXConfig.objectLaTeX()); | |
// Specify the output working directory for the output file | |
options.setOutputWorkingDirectory(new OutputFileSystemDirectory("")); | |
// Initialize the TeXOptions and PngSaveOptions for saving LaTeX to PNG image format | |
PngSaveOptions pngSaveOptions = new PngSaveOptions(); | |
pngSaveOptions.setResolution(300); | |
options.setSaveOptions(pngSaveOptions); | |
// Perform the LaTeX to PNG image rendering using TexJob class | |
new TeXJob("SavedLatex.png", new ImageDevice(), options).run(); | |
} | |
} |
前のトピックでは、Javaを使用してOneNoteNotebookをPDFに変換する方法について説明しました。一方、このトピックでは、単純なアプローチでLaTeXをJavaで画像に変換する方法に焦点を当てました。