How to convert multiple HTML files to a single RTF using C# .NET platform.


For example, there is an online book consisting of a set of HTML files. (As shown in the figure). We’ve a task to convert some html files from this book into single RTF document.


The solution:

Component HTML-to-RTF.Net not only can convert HTML files to RTF, but unite received RTF files into one.

Below is a sample code showing how to convert HTML documents and get a single RTF document:


         SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();

            string[] htmlFiles = Directory.GetFiles(@"c:\htmls\", "*.htm*");
            string singleRtfPath = @"c:\Book.rtf";

            List rtfDocs = new List();

            // Convert each HTML file from "c:\htmls\" into RTF document
            foreach (string htmlFile in htmlFiles)
                rtfDocs.Add(h.ConvertFileToString(htmlFile));

            string singleRtfDoc = String.Empty;
            foreach (string rtfDoc in rtfDocs)
                singleRtfDoc = h.MergeRtfString(singleRtfDoc, rtfDoc);

            File.WriteAllText(singleRtfPath, singleRtfDoc);
                    

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:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.