The «HTML to RTF .Net» is 100% C# managed assembly which provides to any .Net Framework and Core application these functions:
  • Convert HTML (URL, ASPX, XHTML) to Word (DOCX, RTF, Unicode Text) with CSS, images, tables, Unicode and full text formatting.
  • Merge RTF documents and replace text inside them.

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

Syntax

      
 C#  Visual Basic 
public class HtmlToRtf
Public Class HtmlToRtf

Members

               
 All Members  Constructors   Properties   Methods   Events  
 Public

 Protected
 Instance

 Static 
 Declared

 Inherited
 XNA Framework Only 

 .NET Compact Framework Only 

 MemberDescription
HtmlToRtf()()()
Initializes a new instance of the SautinSoft.HtmlToRtf class.
HtmlToRtf(String)
Initializes a new instance of the SautinSoft.HtmlToRtf.
BaseURL
It's target path of HTML document base location.
BeforeImageDownload
Event which appears before downloading http images
BorderVisibility
Set visibility for table's borders: visible, hidden or as in HTML document.
ConvertFile(String, String) Obsolete.
Please use new methods: OpenHtml(), ToDocx(), ToRtf() and ToText() instead. Converts HTML, XHTML, ASPX file/URL to RTF or Text file. Output file will be overwritten.
ConvertFileToString(String) Obsolete.
Please use new methods: OpenHtml(), ToDocx(), ToRtf() and ToText() instead. Converts HTML, XHTML, ASPX file/URL to RTF or Text string
ConvertString(array<Byte>[]()[]) Obsolete.
Please use new methods: OpenHtml(), ToDocx(), ToRtf() and ToText() instead. Converts HTML document to RTF or Text format, depending of the property OutputFormat.
ConvertString(MemoryStream) Obsolete.
Please use new methods: OpenHtml(), ToDocx(), ToRtf() and ToText() instead. Converts HTML document to RTF or Text format, depending of the property OutputFormat.
ConvertString(String) Obsolete.
Please use new methods: OpenHtml(), ToDocx(), ToRtf() and ToText() instead. Converts HTML, XHTML, ASPX string to RTF or Text string.
ConvertString(String, List<(Of <(HtmlToRtf..::.SautinImage>)>)) Obsolete.
ConvertStringToFile(String, String) Obsolete.
Please use new methods: OpenHtml(), ToDocx(), ToRtf() and ToText() instead. Converts HTML, XHTML, ASPX string to RTF or Text file. Output file will be overwritten.
Cookies
Allows to set a credentials to work with password protected HTML documents, e.g. set userName and password
Encoding
Encoding of input HTML
ExceptionList
Allows to get list with all arisen exceptions during the one conversion cycle.
HttpImagesTimeout
Gets or sets the time-out value in milliseconds to wait before the request times out. The default value is 100,000 milliseconds (100 seconds).
InputFormat
Set input format: Text or Html.
MergeAndReplaceRtfFileFromFile(String, String, String, String)
Replaces all matches of string "whatReplaceInRtf" in RTF file "rtfSourcePath" by the content of file "wherewithReplaceRtfPath".
MergeAndReplaceRtfFileFromString(String, String, String, String)
Replaces all matches of the textual string "textToReplace" in RTF file "rtfSourcePath" by the RTF string "wherewithReplaceRtf".
MergeAndReplaceRtfString(String, String, String)
Replaces all matches of the string "textToReplace" by the string "wherewithReplaceInRtf" and returns a new RTF document.
MergeOptions
Gets and sets options to merge RTF documents.
MergeRtfFile(String, String, String)
Merge two RTF files and create new sinlge RTF document. Output file will be overwritten.
MergeRtfString(String, String)
Merge two RTF strings and create new sinlge RTF document
OpenHtml(array<Byte>[]()[])
Opens an HTML document from array of bytes. Use this method in pair with: ToRtf(), ToDocx() and ToText().
OpenHtml(Stream)
Opens an HTML document from Stream object. Use this method in pair with: ToRtf(), ToDocx() and ToText().
OpenHtml(String)
Opens an HTML document from String object or from a file or URL. Use this method in pair with: ToRtf(), ToDocx() and ToText().
OutputFormat
Set the output format: DOCX, RTF, Text ansi or Unicode Text.
PageAlignment
Page Alignment.
PageStyle
Set page properties: page size, orientation and page margins.
PreserveAlignment
Preserve alignment as in HTML or set Left to all.
PreserveBackgroundColor
Preserve background color as in HTML or skip.
PreserveFontColor
Preserve font color as in HTML or set Black for whole text.
PreserveFontFace
Preserve font face as in HTML or set a single.
PreserveFontSize
Preserve font size as in HTML or set a single.
PreserveHR
Preserve horizontal rule or skip it.
PreserveHttpCss
Download Remote CSS or skip it.
PreserveHttpImages
Produce only RTF fragment without document header, font table, color and style tables.
PreserveHyperlinks
Preserve Hyperlinks or skip them.
PreserveImages
Preserve images or skip them.
PreserveNestedTables
Preserve nested tables as in HTML.
PreservePageBreaks
Preserve PageBreaks or skip them.
PreserveTables
Preserve Tables or transfer to text.
RtfCompatibility
Set and get how to render the RTF document to keep compatibility with old RTF readers. Default value: ModernRtfReaders.
RtfLanguage
Allows to set a default language for spelling tools.
Serial
Set your activation key.
SetSerial(String)
Set your activation key.
TableFastProcessing
Get and set the value indicating how launch the table auto-fit algorithm: Fast with middle accuracy (true) or Slow with the maximal accuracy (false). Default value: false.
TableFitWidthByPage
Gets or sets a value indicating to automatically decrease a table width if it greater than page width. Default value: true.
TextStyle
Set text properties: font family, size and color.
ToDocx()()()
Converts the HTML document to Docx format. Works only in pair with OpenHtml() methods.
ToDocx(Stream)
Converts the HTML document to Docx format. Works only in pair with OpenHtml() methods.
ToDocx(String)
Converts the HTML document to Docx format. Works only in pair with OpenHtml() methods.
ToRtf()()()
Converts the HTML document to Rtf format. Works only in pair with OpenHtml() methods.
ToRtf(Stream)
Converts the HTML document to Rtf format. Works only in pair with OpenHtml() methods.
ToRtf(String)
Converts the HTML document to Rtf format. Works only in pair with OpenHtml() methods.
ToText()()()
Converts the HTML document to Text format. Works only in pair with OpenHtml() methods.
ToText(Stream)
Converts the HTML document to Text format. Works only in pair with OpenHtml() methods.
ToText(String)
Converts the HTML document to Text format. Works only in pair with OpenHtml() methods.

Remarks





Examples

CopyConvert HTML to RTF and Vice Versa using C#
using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            LoopBetweenHtmlAndRtf(Path.GetFullPath(@"..\..\Start from HTML\start.html"), 10);

            LoopBetweenHtmlAndRtf(Path.GetFullPath(@"..\..\Start from RTF\start.rtf"), 10);

            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }

        // <summary>
        // Converts between HTML to RTF and vice versa multiple times.
        // </summary>
        // <param name="startingFile">A path to RTF or HTML file. Starting file.</param>
        // <param name="loops">The number of conversion cycles.</param>

        public static void LoopBetweenHtmlAndRtf(string startingFile, int loops)
        {
            RtfToHtml r = new RtfToHtml();
            r.ImageStyle.IncludeImageInHtml = true;                        

            HtmlToRtf h = new HtmlToRtf();

            // After purchasing the license, please insert your serial number here to activate the component.
            // h.Serial = "XXXXXXXXX";

            List<string> extns = new List<string>() { ".html", ".rtf" };
            if (Path.GetExtension(startingFile).ToLower() == ".rtf")
                extns.Reverse();

            string input = File.ReadAllText(startingFile);
            string output = String.Empty;
            string workingDir = Path.GetDirectoryName(startingFile);
            string fileName = String.Empty;

            Console.WriteLine("***** Conversion Started *****");

            for (int i = 0; i < loops; i++)
            {
                // RTF to HTML
                if (extns[0] == ".rtf")
                {
                    r.OpenRtf(input);
                    output = r.ToHtml();
                    fileName = Path.Combine(workingDir, String.Format("{0}.html", i + 1));
                }

                // HTML to RTF
                else
                {
                    h.OpenHtml(input);
                    output = h.ToRtf();
                    fileName = Path.Combine(workingDir, String.Format("{0}.rtf", i + 1));
                }
                Console.WriteLine(Path.GetFileName(fileName));
                File.WriteAllText(fileName, output);
                extns.Reverse();
                input = output;
            }
            Console.WriteLine("***** Conversion Finished *****");
        }
    }
}
CopyConvert HTML to RTF and Vice Versa using VB.Net
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Text
Imports SautinSoft

Module Module1
    Sub Main()
        LoopBetweenHtmlAndRtf(Path.GetFullPath("..\Start from HTML\start.html"), 10)
        LoopBetweenHtmlAndRtf(Path.GetFullPath("..\Start from RTF\start.rtf"), 10)
        Console.WriteLine("Press any key...")
        Console.ReadKey()
    End Sub
    ''' <summary>
    ''' Converts between HTML to RTF and vice versa multiple times.
    ''' </summary>
    ''' <param name="startingFile">A path to RTF or HTML file. Starting file.</param>
    ''' <param name="loops">The number of conversion cycles.</param>
    Public Sub LoopBetweenHtmlAndRtf(ByVal startingFile As String, ByVal loops As Integer)

        Dim r As New RtfToHtml()
        r.ImageStyle.IncludeImageInHtml = True

        Dim h As New HtmlToRtf()

        ' After purchasing the license, please insert your serial number here to activate the component.
        'h.Serial = "XXXXXXXXX"


        Dim extns As New List(Of String)() From {".html", ".rtf"}
        If Path.GetExtension(startingFile).ToLower() = ".rtf" Then
            extns.Reverse()
        End If

        Dim input As String = File.ReadAllText(startingFile)
        Dim output As String = String.Empty
        Dim workingDir As String = Path.GetDirectoryName(startingFile)
        Dim fileName As String = String.Empty

        Console.WriteLine("***** Conversion Started *****")

        For i As Integer = 0 To loops - 1

            ' RTF to HTML
            If extns(0) = ".rtf" Then
                r.OpenRtf(input)
                output = r.ToHtml()
                fileName = Path.Combine(workingDir, String.Format("{0}.html", i + 1))

                ' HTML to RTF
            Else
                h.OpenHtml(input)
                output = h.ToRtf()
                fileName = Path.Combine(workingDir, String.Format("{0}.rtf", i + 1))
            End If
            Console.WriteLine(Path.GetFileName(fileName))
            File.WriteAllText(fileName, output)
            extns.Reverse()
            input = output
        Next i
        Console.WriteLine("***** Conversion Finished *****")
    End Sub
End Module

Inheritance Hierarchy

System..::.Object
  SautinSoft..::.HtmlToRtf

See Also