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

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

Syntax

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

Parameters

inputString
String
Any string in RTF format

Return Value

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

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 rth = new SautinSoft.RtfToHtml();
            //this property is necessary only for registered version
            //rth.Serial = "XXXXXXXXXXXXX";

            //specify some options
            rth.OutputFormat = SautinSoft.eOutputFormat.XHTML_10;
            rth.Encoding = SautinSoft.eEncoding.UTF_8;

            string rtfFile = @"..\..\..\..\..\test.rtf";
            string htmlFile = @"..\..\..\..\..\test.html";
            string rtfString = null;
            string htmlString = null;
            ReadFromFile(rtfFile,ref rtfString);

            htmlString = rth.ConvertString(rtfString);
            if (htmlString != "")
            {
                System.Console.WriteLine("Converted successfully!");
                WriteToFile(htmlFile,htmlString);
                System.Diagnostics.Process.Start(htmlFile);
            }
            else
                System.Console.WriteLine("Converting Error!");
        }

        public static int ReadFromFile(string fileName,ref string fileStr)
        {
            try
            {
                FileInfo fi = new FileInfo(fileName);
                StreamReader strmRead = fi.OpenText();
                fileStr = strmRead.ReadToEnd();
                strmRead.Close();
                return 0;
            }
            catch 
            {
                //error open file
                System.Console.WriteLine("Error in open file");
                return 1;
            }
        }
        public static int WriteToFile(string fileName, string fileStr)
        {
            try
            {
                StreamWriter sw = new StreamWriter(fileName, false);
                sw.Write(fileStr);
                sw.Close();
            }
            catch
            {
                return 2;
            }
            return 0;
        }
    }
}
CopyHow to convert RTF string into HTML string in VB.Net
Imports System
Imports System.IO
Imports System.Text

Namespace SampleConvert
    Friend Class Class1
        Shared Sub Main(ByVal args() As String)
            Dim rth As New SautinSoft.RtfToHtml()
            'this property is necessary only for registered version
            'rth.Serial = "XXXXXXXXXXXXX";


            'specify some options
            rth.OutputFormat = SautinSoft.eOutputFormat.XHTML_10
            rth.Encoding = SautinSoft.eEncoding.UTF_8

            Dim rtfFile As String = "..\..\..\..\..\test.rtf"
            Dim htmlFile As String = "..\..\..\..\..\test.html"
            Dim rtfString As String = Nothing
            Dim htmlString As String = Nothing
            ReadFromFile(rtfFile,rtfString)

            htmlString = rth.ConvertString(rtfString)
            If htmlString <> "" Then
                System.Console.WriteLine("Converted successfully!")
                WriteToFile(htmlFile,htmlString)
                System.Diagnostics.Process.Start(htmlFile)
            Else
                System.Console.WriteLine("Converting Error!")
            End If
        End Sub

        Public Shared Function ReadFromFile(ByVal fileName As String, ByRef fileStr As String) As Integer
            Try
                Dim fi As New FileInfo(fileName)
                Dim strmRead As StreamReader = fi.OpenText()
                fileStr = strmRead.ReadToEnd()
                strmRead.Close()
                Return 0
            Catch
                'error open file
                System.Console.WriteLine("Error in open file")
                Return 1
            End Try
        End Function
        Public Shared Function WriteToFile(ByVal fileName As String, ByVal fileStr As String) As Integer
            Try
                Dim sw As New StreamWriter(fileName, False)
                sw.Write(fileStr)
                sw.Close()
            Catch
                Return 2
            End Try
            Return 0
        End Function
    End Class
End Namespace

See Also