本基础教程涵盖了如何在 C# 中将 TeX 转换为 PDF。它涵盖了系统配置信息、分步过程和可运行的代码示例,以在 C# 中将 LaTeX 转换为 PDF。您只需加载输入 TeX 文件并将其导出为 PDF 文档,并调用几个 API。
使用 C# 将 TeX 转换为 PDF 的步骤
- 在您的系统中配置 Aspose.TeX API 以转换 TeX 文件
- 使用 TeXOptions 类创建转换选项
- 使用 PdfSaveOptions 类初始化以 PDF 格式保存的选项
- 运行 LaTeX 到 PDF 文件的转换
这些步骤用简单的话概括了整个转换过程。首先,初始化一个 TeXOptions 类的对象,并为输出文件设置 PdfSaveOptions。随后,运行 TexJob 将 TeX 文档转换为 C# 中的 PDF。您可以根据需要选择将输出文件导出到流或文件。
在 C# 中将 TeX 转换为 PDF 的代码
using System; | |
using System.IO; | |
namespace AsposeProjects | |
{ | |
class Program | |
{ | |
static void Main(string[] args) // Main function to convert TeX to PDF in C# | |
{ | |
// Initialize license | |
Aspose.TeX.License licTeX = new Aspose.TeX.License(); | |
licTeX.SetLicense("Aspose.Total.lic"); | |
// Declare TeXOptions object to set conversion options | |
Aspose.TeX.TeXOptions options = Aspose.TeX.TeXOptions.ConsoleAppOptions(Aspose.TeX.TeXConfig.ObjectLaTeX); | |
// Set the output directory | |
options.OutputWorkingDirectory = new Aspose.TeX.IO.OutputFileSystemDirectory(Directory.GetCurrentDirectory()); | |
// Initialize PdfSaveoptions class object | |
options.SaveOptions = new Aspose.TeX.Presentation.Pdf.PdfSaveOptions(); | |
// Transform LaTeX to PDF | |
new Aspose.TeX.TeXJob("Input.ltx", new Aspose.TeX.Presentation.Pdf.PdfDevice(), options).Run(); | |
Console.WriteLine("Done"); | |
} | |
} | |
} |
此代码片段可用于在 C#* 中创建 *TeX 到 PDF 转换器。它获取 ObjecTeX 引擎的配置,然后将输出目录设置为创建日志文件和其他资源的位置。在最后一步中,运行 TexJob 以运行渲染引擎,同时传递输入 TeX 文件和输出 PDF 文档的名称。
本教程解释了在 C#* 中将 *TeX 文件转换为 PDF 的详细信息。但是,如果您想学习 LaTeX 到 PNG 的渲染,请参阅 如何在 C# 中将 LaTeX 渲染为 PNG 上的文章。