带有 .rtf 文件扩展名的文件是一种富文本(Rich Text Format)格式文件,可以被大多数的文字处理程序打开,也很方便编辑。但在日常工作中,如果需要共享和打印文档,建议将 RTF 转换为 PDF 进行进一步处理。本文,将通过 C# 及 VB.NET 程序向您展示如何使用 Spire.Doc for .NET 将 RTF 转换为 PDF。
安装 Spire.Doc for .NET
首先,您需要添加 Spire.Doc for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从 此链接 下载或通过 NuGet 安装。
PM> Install-Package Spire.Doc将 RTF 转为 PDF
Spire.Doc for .NET 提供了方法可直接用于加载 RTF 文档,并通过以下步骤将 RTF 转为 PDF:
- 创建 Document 类的实例。
- 调用 Document.LoadFromFile(string fileName, FileFormat fileFormat) 方法加载 RTF 文件。
- 使用 Document.SaveToFile(string fileName, FileFormat fileFormat) 方法保存为 PDF 格式到指定路径。
- C#
- VB.NET
using Spire.Doc;
namespace RTFtoPDF
{
class Program
{
static void Main(string[] args)
{
//创建Document类的实例
Document doc = new Document();
//加载RTF文档
doc.LoadFromFile("http://cdn.e-iceblue.cn/sample.rtf", FileFormat.Rtf);
//保存为PDF格式
doc.SaveToFile("RTFtoPDF.pdf", FileFormat.PDF);
}
}
}Imports Spire.Doc
Namespace RTFtoPDF
Class Program
Private Shared Sub Main(args As String())
'创建Document类的实例 Dim doc As New Document() '加载RTF文档
doc.LoadFromFile("http://cdn.e-iceblue.cn/sample.rtf", FileFormat.Rtf)
'保存为PDF格式 doc.SaveToFile("RTFtoPDF.pdf",FileFormat.PDF) End Sub End Class End Namespace
申请临时 License
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。







