Convert Rtf via Xaml to Html including images. The code is adapted from Matthew Manelas Codesample with a few tweaks:
-
Usage of
RichTextBoxis avoided so we do not need to work around STA issues. Instead we useTextEditorCopyPaste.ConvertRtfToXamlvia reflection. This is basically the same as usingTextRangeBase.Save(..., DataFormats.XamlPackage)withRichTextBoxbut feels a bit cleaner to me. -
Added support for processing the zipped
XamlPackagestream including images. RequiresZipArchivefromSystem.IO.Compressionin .NET 4.5
Simple conversion between Rtf and Xaml is also included by just exposing Microsofts internal implementations.
var rtf = File.ReadAllText("doc.rtf");
var htmlResult = RtfToHtmlConverter.RtfToHtml(rtf, "doc");
htmlResult.WriteToFile("doc.html");var rtf = File.ReadAllText("doc.rtf");
var xaml = RtfToXamlConverter.RtfToXaml(rtf);
File.WriteAllText("doc.xaml", xaml);var rtf = File.ReadAllText("doc.rtf");
using (var xamlStream = RtfToXamlConverter.RtfToXamlPackage(rtf))
File.WriteAllBytes("doc.xap", xamlStream.ToArray());var rtf = File.ReadAllText("doc.rtf");
var plainText = RtfToPlaintTextConverter.RtfToPlainText(rtf);
File.WriteAllText("doc.txt", plainText);