Convert RTF to HTML in .NET

别来无恙 提交于 2019-12-11 01:31:03

问题


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

But how would I convert RTF to HTML?


回答1:


Disclaimer: I'm working for this company.

As I see, the question is old but maybe someone search solution for this too. Our component RTF to HTML allows to convert RTF to HTML. You may download a component or try online-demo. Try the trial version first if you have a doubt. :) Trial is free.

Here's the code sample for the converting from RTF to HTML in ASP.NET:

    SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
    r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_401;
    r.ImageStyle.IncludeImageInHtml = false; //To save images inside HTML as binary data specify this property to 'true'

    r.ImageStyle.ImageFolder = Server.MapPath(""); 
    r.ImageStyle.ImageSubFolder = "images";
    r.ImageStyle.ImageFileName = "picture";       

    string rtf = ".....";
    string html = r.ConvertString(rtf);        

    //show HTML
    if (html.Length>0)
    {
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = "text/html";
        Response.Write(html);
        Response.Flush();
        Response.End();
    }



回答2:


The only problem is when you work on a budget, additional costs mean lower profit, so I started to develop my own version. The main problem is that at the moment it only supports Bold and Italic, and certain entities (&amp, &copy, &reg, &trade, &euro and &###) and lacks both font and color support, but it is still a work in progress. I am adding font and color, but my headache is that these could come from stylesheets rather than the old fashion html tags.

I am writing this in VB.NET and have posted the startup code on CodeProject

Startup Code




回答3:


If you want to do it programattically you should parse your rtf (is a simple text based file), convert rtf control words to html tags.

Here you can find the rtf specs http://www.biblioscape.com/rtf15_spec.htm

or use an already existing converter: http://sourceforge.net/projects/rtf2html-lite/



来源:https://stackoverflow.com/questions/8988018/convert-rtf-to-html-in-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!