Converts Text/RTF string to Text/HTML/XHTML string
Namespace:
SautinSoftAssembly: SautinSoft.RtfToHtml (in SautinSoft.RtfToHtml.dll) Version: 3.3.8.15
Syntax
| C# | Visual Basic |
Parameters
- inputString
- String
Any string in RTF format
Return Value
string with HTML/XHTML documentnull - in case of converting failed
Examples
using System; using System.IO; using System.Text; namespace SampleConvert { class Class1 { static void Main(string[] args) { SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml(); //this property is necessary only for registered version //r.Serial = "XXXXXXXXXXXXX"; //specify some options r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.XHTML_10; r.Encoding = SautinSoft.RtfToHtml.eEncoding.UTF_8; //specify image options r.ImageStyle.ImageFolder = @"c:\"; //this folder must exist r.ImageStyle.ImageSubFolder = "webs"; //this folder will be created by the component r.ImageStyle.ImageFileName = "picture"; //template name for images r.ImageStyle.IncludeImageInHtml = false;//false - save images on HDD, true - save images inside HTML string rtfFile = @"..\..\..\..\..\test.rtf"; string htmlFile = @"..\..\..\..\..\test.html"; string rtfString = null; string htmlString = null; ReadFromFile(rtfFile,ref rtfString); htmlString = r.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; } } }
Imports System Imports System.IO Imports System.Text Module sample Sub Main() Dim r As New SautinSoft.RtfToHtml() 'this property is necessary only for registered version 'r.Serial = "XXXXXXXXXXXXX"; 'specify some options r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.XHTML_10 r.Encoding = SautinSoft.RtfToHtml.eEncoding.UTF_8 'specify image options r.ImageStyle.ImageFolder = "c:\" 'this folder must exist r.ImageStyle.ImageSubFolder = "webs" 'this folder will be created by the component r.ImageStyle.ImageFileName = "picture" 'template name for images r.ImageStyle.IncludeImageInHtml = False 'False - save images on HDD, True - save images inside HTML 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 = r.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 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("Can't open file!") Return 1 End Try End Function Public 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 Module