Convert RTF to HTML in .NET

后端 未结 4 808
陌清茗
陌清茗 2021-01-19 18:47

I\'ve managed to do the reverse using WebBrowser and RichTextBox.

But how would I convert RTF to HTML?

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-19 19:21

    If you pop-up NuGet and search for "RTF", the most popular result right now looks like RtfPipe; you can install it right there, or via the package manager console via:

    Install-Package RtfPipe
    

    Then in your C#, you can convert RTF to HTML super easily:

    var html = RtfPipe.Rtf.ToHtml(rtf);
    

    According to the readme.md on their GitHub page:

    This library attempts to support the core RTF features documented in the RTF Specification 1.9.1. These features include:

    • Character formatting (bold, italics, color, ...)
    • Tables (including nested tables)
    • Lists
    • Hyperlinks
    • Pictures
    • Heading levels
    • HTML encapsulation (e.g. as performed by Outlook)

    With that said, there are numerous cases for non-trivial documents where the library will not produce the "correct" visual representation when compared to other RTF readers (such as MS Word).

    I piped my RTF into it, and it worked amazingly. YYMV.

提交回复
热议问题