最近asp.net的项目里需要在网页中对数据库中存储的rtf数据进行显示和编辑。上网查找可用插件,找到功能强大的CuteEditor,遂上网查找到其安装使用方法(http://www.cnblogs.com/luluping/archive/2010/10/06/1844753.html)。然而装好了后却不知如何转化rtf显示为HTML,上网搜索很久未果。后来突然想到安装包里有帮助文件,查看果然有转化的详细方法如下:
1. RTF to HTML
In order to convert RTF to HTML, you would use LoadRTF Method:
LoadRTF Method
Loads the contents of an RTF into the CuteEditor control
// Load RTF string
string t = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20 Hello\par } "; Editor1.LoadRTF(t);// Load RTF file
Editor1.LoadRTF("document.rtf");
2. HTML to RTF
In order to convert HTML to RTF, you would use SaveRTF Method:
SaveRTF Method
Saves the contents of the Cute Editor to a RTF file. The SaveRTF method enables you to save the entire contents of the control to a RTF file. If the file name that is passed to the path parameter already exists at the specified directory, the file will be overwritten without notice. You can use the LoadFile, LoadWord, LoadRTF, LoadText method to load the contents of a file into the CuteEditor
// Saves the contents of the Cute Editor to a RTF file
Editor1.SaveRTF("document.rtf");
3. Convert HTML to RTF directly
//Convert HTML to RTF directly
string t="<b>Hello world</b>"; CuteEditor.Convertor.RTF.HTML2RTF html2rtf = new CuteEditor.Convertor.RTF.HTML2RTF(t); textbox1.Text = html2rtf.RTF; // Get the RTF string using the RTF property