Skip to content

Instantly share code, notes, and snippets.

@zhanghuabin
Last active December 29, 2015 17:29
Show Gist options
  • Save zhanghuabin/7704115 to your computer and use it in GitHub Desktop.
Save zhanghuabin/7704115 to your computer and use it in GitHub Desktop.
Use Swing API to convert a simple RTF-format file to HTML-format.
import javax.swing.JEditorPane
(args[0] as File).withReader {
def p = new JEditorPane()
p.contentType = 'text/rtf'
def kitRtf = p.getEditorKitForContentType p.contentType
kitRtf.read it, p.document, 0
def kitHtml = p.getEditorKitForContentType 'text/html'
def out = new StringWriter()
kitHtml.write out, p.document, 0, p.document.length
println out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment