Converts HTML, XHTML, ASPX file/URL to RTF or Text string

Namespace:  SautinSoft
Assembly:  SautinSoft.HtmlToRtf (in SautinSoft.HtmlToRtf.dll) Version: 4.6.10.19

Syntax

      
 C#  Visual Basic 
public string ConvertFileToString(
	string htmlFile
)
Public Function ConvertFileToString ( _
	htmlFile As String _
) As String

Parameters

htmlFile
String
Path to local HTML file or URL

Return Value

String with RTF or Text document, depends of OutputFormat
null - in case of converting failed

Remarks



Examples

CopyHow to convert URL to Word-RTF in memory in C#
using System;
using System.IO;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {

            //Convert URL to Word-RTF in memory
            //If you need more information about HTML-to-RTF Pro DLL .Net email us at:
            //support[at]sautinsoft.com        

            SautinSoft.HtmlToRtf objH = new SautinSoft.HtmlToRtf();
            //objH.Serial = "XXXXXXXXXXXXXXX";


            //set some options
            objH.PageStyle.PageSize.Letter();
            objH.PageStyle.PageMarginLeft.mm(20f);

            string htmlUrl=@"http://www.sautinsoft.net";
            string word="";

            //2. Convert HTML url to RTF in memory            
            word = objH.ConvertFileToString(htmlUrl);

            if(word!="")
            {
                //3. Save to RTF document
                int ret = WriteToFile(@"..\..\..\..\..\..\Testing HTMLs\Word document.rtf",word);
                if (ret==0)
                    System.Diagnostics.Process.Start(@"..\..\..\..\..\..\Testing HTMLs\Word document.rtf");
            }
        }
        public static string ReadFileString(string path)
         {    
             using (StreamReader reader = new StreamReader(path))
             {                
                 return reader.ReadToEnd();
             }

         }
        public static int WriteToFile(string fileName, string contents)
        {
            try
            {
                StreamWriter sw = new StreamWriter(fileName);
                sw.Write(contents);
                sw.Close();                
            }
            catch
            {
                return 2;
            }
            return 0;
        }

    }
}
CopyHow to convert URL to Word-RTF in memory in VB.Net
Imports System
Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        'Convert URL to Word-RTF in memory
        'If you need more information about HTML-to-RTF Pro DLL .Net email us at:
        'support[at]sautinsoft.com        


        Dim objH As New SautinSoft.HtmlToRtf
        'objH.Serial = "XXXXXXXXXXXXXXX";



        'set some options
        objH.PageStyle.PageSize.Letter()
        objH.PageStyle.PageMarginLeft.mm(20.0F)

        Dim htmlUrl As String = "http://www.sautinsoft.net"
        Dim word As String = ""

        '2. Convert HTML url to RTF in memory            
        word = objH.ConvertFileToString(htmlUrl)

        If word <> "" Then
            '3. Save to RTF document
            Dim ret As Integer = WriteToFile("..\..\..\..\..\Testing HTMLs\Word document.rtf", word)
            If ret = 0 Then
                System.Diagnostics.Process.Start("..\..\..\..\..\Testing HTMLs\Word document.rtf")
            End If
        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

See Also