Last active
December 29, 2015 17:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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