How to write a function to convert Text to HTML in C# for 15 minutes?

RTF to HTML .Net

.Net assembly to convert Text, RTF and DOCX to HTML 3.2, 4.01, XHTML and HTML5 in .Net and C#.
How to write a function to convert Text to HTML in C# for 15 minutes?

RTF to HTML .Net

How to write a function to convert Text to HTML in C# for 15 minutes?
How to write a function to convert Text to HTML in C# for 15 minutes?

Introduction

Imagine, that in 15 minutes after reading this text you will be able to provide API for your application to convert Text documents into HTML, using C# or VB.Net.


                 SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
string textFile = @"c:\The Egypt In My Looking Glass.txt";
string htmlFile = @"c:\The Egypt In My Looking Glass.html";

r.OutputFormat = RtfToHtml.eOutputFormat.HTML_5;
r.ConvertFile(textFile, htmlFile);
          

The library gives you a full set of API to convert Text to HTML. Furthermore, during conversion to HTML you may adjust following:

  • Various output format: HTML 3.2, HTML 4.01, HTML 5, XHTML, Text.
  • Generating output document in plain HTML 3.2 without CSS.
  • Save CSS data between tags <style>...</style> or as inline styles <tag style="...">.
  • Specify encoding of output HTML.
  • Set up document Title; create only the part of HTML between <body>...</body> tags.
  • Set up a common font, size and color for a whole document.
  • Detect hyperlinks from text and make them real hyperlinks.
  • Specify the table borders visibility.

Download

To see this functionality firsthand, download the freshest «RTF to HTML .Net» with code examples, 51.8 Mb.

Limitations

RTF to HTML .Net The limitations of the free version are: The trial notice "Created by unlicensed version of RTF to HTML .Net" and the random addition of the word "TRIAL".


Some examples to convert Text to HTML in C# and VB.Net

1. Convert Text file to HTML file in C#:

            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
            string textFile = @"d:\The Librarian.txt";
            string htmlFile = Path.ChangeExtension(textFile, ".html");

            r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_5;
            if (r.ConvertFile(textFile, htmlFile)==0)
            {
                // Open HTML in browser.
                System.Diagnostics.Process.Start(htmlFile);
            }
2. Convert Text to HTML in memory using C#.
            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
            string textFile = @"d:\The Lynx.txt";
            string textString = File.ReadAllText(textFile);

            string htmlString = r.ConvertString(textString);
3. Convert Text to HTML in VB.Net; make all CSS styles inline, i.e. put within the attribute style="...".
            Dim r As New SautinSoft.RtfToHtml()

            ' Set HTML5 format.
            r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_5
            ' Set utf-8 encoding.
            r.Encoding = SautinSoft.RtfToHtml.eEncoding.UTF_8
            ' Make all CSS inline.
            r.TextStyle.InlineCSS = True

            Dim textFile As String = "e:\Returns and Exchanges.txt"
            Dim htmlFile As String = Path.ChangeExtension(textFile, ".html")
            r.ConvertFile(textFile, htmlFile)

Requirements and Technical Information

В«RTF to HTML .NetВ» can be used on 32 and 64-bits platforms with .NET Framework 4.0 and higher, .NET Core 2.0 and higher. The component doesn't require Internet Explorer, Microsoft Office or any other software. It's absolutely standalone and independent library.

The DOCX conversion works starting from .NET Framework 4.0 and higher, .NET Core 2.0 and higher. If you are looking for a standalone C# library to create and parse Word documents, try our Document .Net.

Our product is compatible with all .NET languages and supports all Operating Systems where .NET Framework can be used. Note that В«RTF to HTML .NetВ» is entirely written in managed C#.

.Net Framework 4.0 and higher and .Net Core 2.0 and higher

.NET Framework 4.0, 4.5, 4.6.1 and higher.

.NET Standard 2.0

.NET Core 2.0 and higher.


Multi-platform component, runs on:


Our component has proven itself on cloud platforms and services:

  • Microsoft Azure
  • Amazon Web Services (AWS)
  • Google Cloud Platform
  • SharePoint
  • Docker
  • etc.

If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: