C#/VB.NET:Convert Word to RTF
RTF is the abbreviation of Rich Text Format, which means multi-text format, and files such as images can be embedded in RTF documents. This is the document format that Word can save for compatibility with other Word processing software. This article will introduce how to convert Word to RTF format through Spire.Doc for .NET.
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via
NuGet .
PM> Install-Package Spire.Doc
Here are the steps:
l Create Word document
l Using the document.LoadFromFile ()method to load the file from disk.
l Using document.SaveToFile() method to save the file in RTF format.
Full Code:
[C#]
using System;
using Spire.Doc;
using Spire.Doc.Documents;
namespace ConvertToRtf
{
public partial class Form1 : Form
{
publicForm1 ()
{
InitializeComponent();
}
private void button1_Click( object sender, EventArgs e)
{ //Create Word document
Document document = new Document();
document.LoadFromFile( @"..\..\..\..\..\..\Data\ToRtf.doc" );
//Save doc file.
document.SaveToFile( "Sample.rtf" , FileFormat.Rtf);
//Launching the MS Word file.
WordDocViewer( "Sample.rtf" );
}
[VB.NET]
Import's system
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace ConvertToRtf
Public Class Form1
Inherits Form
Public Sub New ()
MyBase . New
InitializeComponent
End Sub
Private Sub button1_Click( ByVal sender As Object , ByVal e As EventArgs)
'Create Word document
Dim document As Document = New Document
document.LoadFromFile( "ToRtf.doc" )
'Save doc file.
document.SaveToFile( "Sample.rtf" , FileFormat.Rtf)
'Launching the MS Word file.
WordDocViewer( "Sample.rtf" )
End Sub
End Class
End Namespace
ATTENTION:
The code path is for reference only, and you can customize the path as you want.
Conclusion:
In this article, you have learned how to convert Word to RTF. What's more, we also have some other functions, such as, converting Word to TXT , Word to Image , Word to PDF , etc. If you'd like to learn more, please click on the link blow: https://www. e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/Spire.Doc-Program-Guide-Content.html
Comments
Post a Comment