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 doc:

 
            SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();
 
            string[] htmlFiles = Directory.GetFiles(@"c:\htmls\", "*.htm*");
            string singleRtfPath = @"c:\Book.rtf";
 
 
            List<string> rtfDocs = new List<string>();
 
            // 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);
Share on Facebook

Leave a Comment

Your email address will not be published.