Converts HTML, XHTML, ASPX string to RTF or Text string

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

Syntax

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

Parameters

htmlString
String
Any string in HTML format, even piece of HTML code

Return Value

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

Remarks



Examples

CopyConvert HTML to Word in memory using C#
using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // Convert HTML to RTF in memory
            // If you need more information about "HTML to RTF .Net" email us at:
            // support[at]sautinsoft.com        
            SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();
            // After purchasing the license, please insert your serial number here to activate the component
            //h.Serial = "XXXXXXXXXXXXXXX";

            DirectoryInfo htmlDir = new DirectoryInfo(@"..\..\..\..\..\..\Testing HTMLs");
            string htmlFile = Path.Combine(htmlDir.FullName, "sample doc.html");
            string rtfFile = Path.ChangeExtension(htmlFile, ".rtf");

            // Assume that we already have HTML as string object.
            string htmlString = File.ReadAllText(htmlFile);

            // Set BaseUrl to transform relative paths into absolute.
            h.BaseURL = htmlDir.FullName;

            // Convert HTML to RTF in memory.
            string rtfString = h.ConvertString(htmlString);

            if (rtfString!=null)
            {
                File.WriteAllText(rtfFile, rtfString);
                Console.WriteLine("Converted successfully!");
                System.Diagnostics.Process.Start(rtfFile);
            }
            else
            {
                Console.WriteLine("Converting failed!");
                Console.ReadLine();
            }
        }
    }
}
CopyConvert HTML to Word in memory using VB.Net
using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // Convert HTML to RTF in memory
            // If you need more information about "HTML to RTF .Net" email us at:
            // support[at]sautinsoft.com        
            SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();
            // After purchasing the license, please insert your serial number here to activate the component
            //h.Serial = "XXXXXXXXXXXXXXX";

            DirectoryInfo htmlDir = new DirectoryInfo(@"..\..\..\..\..\..\Testing HTMLs");
            string htmlFile = Path.Combine(htmlDir.FullName, "sample doc.html");
            string rtfFile = Path.ChangeExtension(htmlFile, ".rtf");

            // Assume that we already have HTML as string object.
            string htmlString = File.ReadAllText(htmlFile);

            // Set BaseUrl to transform relative paths into absolute.
            h.BaseURL = htmlDir.FullName;

            // Convert HTML to RTF in memory.
            string rtfString = h.ConvertString(htmlString);

            if (rtfString!=null)
            {
                File.WriteAllText(rtfFile, rtfString);
                Console.WriteLine("Converted successfully!");
                System.Diagnostics.Process.Start(rtfFile);
            }
            else
            {
                Console.WriteLine("Converting failed!");
                Console.ReadLine();
            }
        }
    }
}

See Also