Converts Text/RTF string to Text/HTML/XHTML string

Namespace:  SautinSoft
Assembly:  SautinSoft.RtfToHtml (in SautinSoft.RtfToHtml.dll) Version: 6.2.2.1

Syntax

      
 C#  Visual Basic 
public string ConvertString(
	string inputString
)
Public Function ConvertString ( _
	inputString As String _
) As String

Parameters

inputString
String
Any string in RTF format

Return Value

string with HTML/XHTML document
null - in case of converting failed

Remarks

Examples

CopyHow to convert RTF string into HTML string in C#
using System;
using System.IO;
using System.Text;

namespace SampleConvert
{
    class Class1
    {
        static void Main(string[] args)
        {
            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
            string AppPath=System.Environment.CurrentDirectory;

            //specify some options
            r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_5;
            r.Encoding = SautinSoft.RtfToHtml.eEncoding.UTF_8;

            //specify image options
            r.ImageStyle.ImageFolder = AppPath;            //this folder must exist
            r.ImageStyle.ImageSubFolder = "test.files";    //this folder will be created by the component
            r.ImageStyle.ImageFileName = "img";            //template name for images
            r.ImageStyle.IncludeImageInHtml = false;    //false - save images on HDD, true - save images inside HTML


            string rtfFile = Path.GetFullPath(@"..\..\..\..\..\test.rtf");
            string htmlFile = Path.Combine(AppPath,"test.html"); //the result will be located in the same folder as binary
            string rtfString = String.Empty;
            string htmlString = String.Empty;

            rtfString = File.ReadAllText(rtfFile);

            htmlString = r.ConvertString(rtfString);

            if (!String.IsNullOrEmpty(htmlString))
            {
                System.Console.WriteLine("Converted successfully!");
                File.WriteAllText(htmlFile, htmlString);
                System.Diagnostics.Process.Start(htmlFile);
            }
            else
            {
                System.Console.WriteLine("Conversion failed!");
                Console.ReadLine();
            }
        }
    }
}
CopyHow to convert RTF string into HTML string in VB.Net
Imports System.IO
Imports System.Text

Namespace SampleConvert
    Friend Class Class1
        Shared Sub Main(ByVal args() As String)
            Dim r As New SautinSoft.RtfToHtml()
            Dim AppPath As String = System.Environment.CurrentDirectory

            'specify some options
            r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_5
            r.Encoding = SautinSoft.RtfToHtml.eEncoding.UTF_8

            'specify image options
            r.ImageStyle.ImageFolder = AppPath 'this folder must exist
            r.ImageStyle.ImageSubFolder = "test.files" 'this folder will be created by the component
            r.ImageStyle.ImageFileName = "img" 'template name for images
            r.ImageStyle.IncludeImageInHtml = False 'false - save images on HDD, true - save images inside HTML



            Dim rtfFile As String = Path.GetFullPath("..\..\..\..\..\test.rtf")
            Dim htmlFile As String = Path.Combine(AppPath, "test.html") 'the result will be located in the same folder as binary
            Dim rtfString As String = String.Empty
            Dim htmlString As String = String.Empty

            rtfString = File.ReadAllText(rtfFile)

            htmlString = r.ConvertString(rtfString)

            If Not String.IsNullOrEmpty(htmlString) Then
                System.Console.WriteLine("Converted successfully!")
                File.WriteAllText(htmlFile, htmlString)
                System.Diagnostics.Process.Start(htmlFile)
            Else
                System.Console.WriteLine("Conversion failed!")
                Console.ReadLine()
            End If
        End Sub
    End Class
End Namespace

See Also