Question

I'm using GWT Richtextbox, But this widget shows values which are simple text or HTML formatted. Is there any way to show RTF data in a GWT-Richtext or GWT-htmlEditor widget? Or is there a widget in other GWT libraries which will do this?

Was it helpful?

Solution

I don't think so. About year ago we wanted to develop rtf browser on client side and we failed. There is no GWT-Rtf libraries. You could try to find something written in javascript and then wrap it with JSNI, but I haven't seen such library as well. Someone told me that it might be possible with Activex, but we haven't even tried this method.

OTHER TIPS

What are you trying to achieve? If you want to share documents with an RTF editor like, say, Microsoft Word, you should check to see if that editor can also work with HTML. I know that MS Word can edit HTML.

Alternatively, you might consider transposing RTF into HTML and back again on the server side. There are several Java libraries out there for doing that, and I believe that Flying Saucer is one of them.

You could use RTFEditorKit in combination with HTMLEditorKit to convert between the two server-side or in an applet. This way you can use GWT's rich text editor and output or input RTF.

public static String getHtmlFromRtf(InputStream fi){
    Writer sOut = new StringWriter();
    DefaultStyledDocument doc = new DefaultStyledDocument();                  
    HTMLEditorKit htmlKit = new HTMLEditorKit();                  
    RTFEditorKit rtf = new RTFEditorKit();

    try
    {
        rtf.read( fi, doc, 0 );
        htmlKit.write(sOut, doc, 0, doc.getLength());
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    catch (BadLocationException e)
    {
        e.printStackTrace();
    }
    return sOut.toString();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top