public static void ConvertHtmlToTextString() { SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf(); // After purchasing the license, please insert your serial number here to activate the component. // h.Serial = "XXXXXXXXX"; string inputFile = @"..\..\Sample.html"; string outputFile = "Result.txt"; // Read our HTML file a string. string htmlString = File.ReadAllText(inputFile); if (h.OpenHtml(htmlString)) { string textString = h.ToText(); // Open the result for demonstration purposes. if (!String.IsNullOrEmpty(textString)) { File.WriteAllText(outputFile, textString); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outputFile) { UseShellExecute = true }); } } }
public static void ConvertHtmlToTextStream() { SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf(); // After purchasing the license, please insert your serial number here to activate the component. // h.Serial = "XXXXXXXXX"; string inputFile = @"..\..\Sample.html"; string outputFile = "Result.txt"; using (FileStream htmlFileStrem = new FileStream(inputFile, FileMode.Open)) { if (h.OpenHtml(htmlFileStrem)) { using (MemoryStream ms = new MemoryStream()) { bool ok = h.ToText(ms); // Open the result for demonstration purposes. if (ok) { File.WriteAllBytes(outputFile, ms.ToArray()); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outputFile) { UseShellExecute = true }); } } } } }
public static void ConvertMultipleHtmlToText() { SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf(); // After purchasing the license, please insert your serial number here to activate the component. // h.Serial = "XXXXXXXXX"; string inpFolder = @"..\..\Testing HTMLs\"; string outFolder = new DirectoryInfo(Directory.GetCurrentDirectory()).CreateSubdirectory("Text").FullName; string[] inpFiles = Directory.GetFiles(inpFolder, "*.htm*"); int total = inpFiles.Length; int currCount = 1; int successCount = 0; foreach (string inpFile in inpFiles) { string fileName = Path.GetFileName(inpFile); Console.Write("{0:D2} of {1} ... {2}", currCount, total, fileName); currCount++; bool ok = true; if (h.OpenHtml(inpFile)) { string outFile = Path.Combine(outFolder, Path.ChangeExtension(fileName, ".txt")); if (h.ToText(outFile)) { successCount++; } else { ok = false; } } else { ok = false; } Console.WriteLine(" ({0})", ok); } Console.WriteLine("{0} of {1} HTML(s) converted successfully!", successCount, total); Console.WriteLine("Press any key ..."); Console.ReadKey(); // Open the result for demonstration purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFolder) { UseShellExecute = true }); }
private static string ExtractTextWithSautinSoft(string htmlString) { var h = new SautinSoft.HtmlToRtf(); if (!h.OpenHtml(htmlString)) { return(string.Empty); } var rtfString = h.ToText(); return(rtfString); }
public static void ConvertHtmlToTextFile() { SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf(); // After purchasing the license, please insert your serial number here to activate the component. // h.Serial = "XXXXXXXXX"; string inputFile = @"..\..\Sample.html"; string outputFile = "Result.txt"; if (h.OpenHtml(inputFile)) { bool ok = h.ToText(outputFile); // Open the result for demonstration purposes. if (ok) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outputFile) { UseShellExecute = true }); } } }