Converts HTML, XHTML, ASPX file/URL to RTF or Text string
Namespace:
SautinSoftAssembly: SautinSoft.HtmlToRtf (in SautinSoft.HtmlToRtf.dll) Version: 4.1.7.15
Syntax
| C# | Visual Basic |
Parameters
- htmlFile
- String
Path to local HTML file or URL
Return Value
String with RTF or Text document, depends of OutputFormatnull - in case of converting failed
Examples
using System; using System.IO; using System.Text; namespace SampleConvert { class Class1 { static void Main(string[] args) { SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf(); //this property is necessary only for registered version //h.Serial = "XXXXXXXXXXXXX"; //specify some options h.OutputFormat = SautinSoft.HtmlToRtf.eOutputFormat.Rtf; h.Encoding = SautinSoft.HtmlToRtf.eEncoding.AutoSelect; h.PageStyle.PageSize.Letter(); string htmlFile = @"..\..\..\..\..\Test.htm"; string rtfFile = @"..\..\..\..\..\Test.rtf"; string rtfString = ""; rtfString = h.ConvertFileToString(htmlFile); if (rtfString != "") { System.Console.WriteLine("Converted successfully!"); WriteToFile(rtfFile,rtfString); System.Diagnostics.Process.Start(rtfFile); } else System.Console.WriteLine("Converting Error!"); } 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 Module1 Sub Main() Dim h As New SautinSoft.HtmlToRtf 'this property is necessary only for registered version 'h.Serial = "XXXXXXXXXXXXX"; 'specify some options h.OutputFormat = SautinSoft.HtmlToRtf.eOutputFormat.Rtf h.Encoding = SautinSoft.HtmlToRtf.eEncoding.AutoSelect h.PageStyle.PageSize.Letter() Dim htmlFile As String = "..\..\..\..\Test.htm" Dim rtfFile As String = "..\..\..\..\Test.rtf" Dim rtfString As String = "" rtfString = h.ConvertFileToString(htmlFile) If rtfString <> "" Then System.Console.WriteLine("Converted successfully!") WriteToFile(rtfFile, rtfString) System.Diagnostics.Process.Start(rtfFile) Else System.Console.WriteLine("Converting Error!") End If End Sub 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