如何在 C# 中将 PDF 转换为 RTF

本快速教程重点介绍文档转换过程以及如何在 C#** 中将 PDF 转换为 RTF。本文提供了执行文档转换的详细逐步信息、如何配置文档转换包以及演示C# PDF 到 RTF 转换器 功能的工作的示例。此外,本指南可用于支持 .NET 环境的任何平台,如 MS Windows、Linux 和 Mac OS,无需设置任何其他软件。

在 C# 中将 PDF 转换为 RTF 的步骤

  1. 从 .NET 应用程序中的 NuGet 包管理器设置 GroupDocs.Conversion for .NET 包以将 PDF 转换为 RTF
  2. 添加对 GroupDocs.Conversion 命名空间的引用以开发 PDF 到 RTF 功能
  3. 初始化 Converter 类并加载输入的 PDF 文档
  4. 通过初始化 WordProcessingConvertOptions 类设置输出 RTF 文档的转换选项
  5. 最后,通过使用 Convert 方法将转换后的 RTF 文件保存到磁盘

C# PDF to RTF 转换器应用程序可以按照上述步骤依次开发。 Converter 类实例使您能够加载源 PDF 文件进行转换,然后 WordProcessingConvertOptions 类允许您定义用于自定义转换后的 RTF 文档的参数。最后,convert 方法允许您将生成的 RTF 文件保存到磁盘。

在 C# 中将 PDF 转换为 RTF 的代码

using System;
using GroupDocs.Conversion.Options.Convert;
namespace ConvertPdfToRtfInCSharp
{
class Program
{
public static void Main(string[] args) // Main function to convert PDF to RTF using C#
{
// Remove the watermark in output RTF document by adding license
string licensePath = "GroupDocs.Conversion.lic";
GroupDocs.Conversion.License lic = new GroupDocs.Conversion.License();
lic.SetLicense(licensePath);
// Load the source PDF file for conversion to RTF
var converterObj = new GroupDocs.Conversion.Converter("sample.pdf");
// Set the conversion options for RTF document to customize the output file
WordProcessingConvertOptions options = new WordProcessingConvertOptions();
// Convert and save the PDF in RTF format
converterObj.Convert("converted.rtf", options);
Console.WriteLine("Done");
}
}
}

在上面的代码片段中,PDF 到 RTF C# 功能是使用文档转换库的简单 API 调用开发的。此示例代码还可用于将文档转换为其他文字处理格式,如 DOC、DOCX、DOT、TXT 等。此外,可以通过使用 WordProcessingConvertOptions 类设置宽度、高度、缩放、Dpi、PageOrientation 等属性来自定义转换后的 RTF 文件。

我们已经讨论了使用 C# 将 PDF 转换为 RTF 的文档转换过程,并为其创建了示例代码。最近,我们发表了一篇使用 C# 将 PDF 转换为 Image 的文章,请查看 如何在 C# 中将 PDF 转换为图像 指南了解更多信息。

 简体中文