Here you can find the source of rtfToHtml(Reader rtf)
Parameter | Description |
---|---|
rtf | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String rtfToHtml(Reader rtf) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import javax.swing.JEditorPane; import javax.swing.text.BadLocationException; import javax.swing.text.EditorKit; public class Main { public static String rtfToHtml(String rtf) throws IOException { return rtfToHtml(new StringReader(rtf)); }/*from w w w . j a va 2s. c o m*/ /** * @see http * ://www.codeproject.com/Tips/136483/Java-How-to-convert-RTF-into-HTML * @param rtf * @return * @throws IOException */ public static String rtfToHtml(Reader rtf) throws IOException { JEditorPane p = new JEditorPane(); p.setContentType("text/rtf"); EditorKit kitRtf = p.getEditorKitForContentType("text/rtf"); try { kitRtf.read(rtf, p.getDocument(), 0); kitRtf = null; EditorKit kitHtml = p.getEditorKitForContentType("text/html"); Writer writer = new StringWriter(); kitHtml.write(writer, p.getDocument(), 0, p.getDocument().getLength()); return writer.toString(); } catch (BadLocationException e) { e.printStackTrace(); } return null; } }