Last active
May 26, 2018 04:41
-
-
Save NtFreX/280934c180f98b8610c0d01d4738a04c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DevExpressConverter | |
{ | |
public static string ConvertRtfToHtml(string rtf) | |
{ | |
var ms = new MemoryStream(); | |
var writer = new StreamWriter(ms); | |
writer.Write(rtf); | |
writer.Flush(); | |
ms.Position = 0; | |
var output = ""; | |
HtmlEditorExtension.Import(HtmlEditorImportFormat.Rtf, ms, (s, enumerable) => output = s); | |
return output; | |
} | |
public static string ConvertHtmlToRtf(string html) | |
{ | |
var ms = new MemoryStream(); | |
var editor = new ASPxHtmlEditor { Html = html }; | |
editor.Export(HtmlEditorExportFormat.Rtf, ms); | |
ms.Position = 0; | |
var reader = new StreamReader(ms); | |
return reader.ReadToEnd(); | |
} | |
} | |
public static class WindowsFormsConverter | |
{ | |
public static string ConvertHtmlToRtf(string html) | |
{ | |
var webBrowser = new WebBrowser { DocumentText = html }; | |
while (webBrowser.DocumentText != html) | |
Application.DoEvents(); | |
if (webBrowser.Document == null) | |
return null; | |
webBrowser.Document.ExecCommand("SelectAll", false, null); | |
webBrowser.Document.ExecCommand("Copy", false, null); | |
var richTextbox = new RichTextBox(); | |
richTextbox.Paste(); | |
return richTextbox.Rtf; | |
} | |
} | |
public static class SautinSoftConverter | |
{ | |
public static string ConvertHtmlToRtf(string html, string licenseSerial, string baseUrl = null) | |
{ | |
var h = new HtmlToRtf { Serial = licenseSerial }; | |
if(baseUrl != null) | |
h.BaseURL = baseUrl; | |
return h.ConvertString(html); | |
} | |
} | |
public static class OpenXmlConverter | |
{ | |
public static byte[] ConvertHtmlToOpenXml(string html) | |
{ | |
using (var generatedDocument = new MemoryStream()) | |
{ | |
using (var package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document)) | |
{ | |
var mainPart = package.MainDocumentPart; | |
if (mainPart == null) | |
{ | |
mainPart = package.AddMainDocumentPart(); | |
new Document(new Body()).Save(mainPart); | |
} | |
var converter = new HtmlConverter(mainPart); | |
converter.ParseHtml(html); | |
mainPart.Document.Save(); | |
} | |
return generatedDocument.ToArray(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment