这个简短的教程解释了如何在 C# 中将 PUB 转换为 PDF。这包含设置环境的初始步骤的详细信息,然后提供算法和代码片段以涵盖与在 C# 中将 Publisher 转换为 PDF 的过程相关的详细信息。此外,您无需安装任何其他工具即可使用源 PUB 文件并将其编写为 PDF 文件。
使用 C# 将 PUB 转换为 PDF 的步骤
- 配置 Aspose.PUB 库以处理 PUB 文件
- 使用 CreateParser 方法加载源发布者文件
- 使用 ConvertToPdf 方法导出输出文件
这里解释了分步算法,以帮助您了解在 C#* 中将 *Publisher 文件导出为 PDF 的过程。 PubFactory 类包括不同的重载方法,用于从文件或流中为 PUB 文件创建解析器。同样,IPdfConverter 类能够将已解析的 PUB 文件转换为 PDF 文档。
在 C# 中将 PUB 转换为 PDF 的代码
using System; | |
namespace AsposeProjects | |
{ | |
class Program | |
{ | |
static void Main(string[] args) // Main function to Unprotect a Word file in C# | |
{ | |
// Initialize licenses | |
Aspose.Pub.License licWords = new Aspose.Pub.License(); | |
licWords.SetLicense("Aspose.Total.lic"); | |
// Load the input Publisher file | |
Aspose.Pub.IPubParser parser = Aspose.Pub.PubFactory.CreateParser("input.pub"); | |
// Parse the source PUB file | |
Aspose.Pub.Document doc = parser.Parse(); | |
// Convert PUB to PDF file | |
Aspose.Pub.PubFactory.CreatePdfConverter().ConvertToPdf(doc, "PUBtoPDF.pdf"); | |
Console.WriteLine("Done"); | |
} | |
} | |
} |
您可以使用此代码片段将 Microsoft Publisher 转换为 C# 中的 PDF。但是,可以对其进行修改以满足您的要求,例如选择从流中加载 PUB 文件还是使用文件路径字符串。在最后一步中,调用 ConvertToPdf 方法来导出输出 PDF 文档,同时传递文件名。
本教程涵盖了在 C#* 中将 *PUB 文件转换为 PDF 的信息。然而,如果您想将 PUB 文件呈现为图像,请阅读 如何在 C# 中将 PUB 转换为 PNG 上的文章。