Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@akhikhl
Created July 14, 2013 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhikhl/5993538 to your computer and use it in GitHub Desktop.
Save akhikhl/5993538 to your computer and use it in GitHub Desktop.
A happier, groovier way to parse RTF: apache_tika + XmlSlurper
package org.akhikhl.test
import org.apache.tika.metadata.Metadata
import org.apache.tika.parser.rtf.RTFParser
class ParseRtf {
def parse(String rtfText) {
// not validating, not ns-aware
XmlSlurper slurper = new XmlSlurper(false, false)
InputStream rtfStream = new ByteArrayInputStream(value.getBytes())
new RTFParser().parse(rtfStream, slurper, new Metadata())
slurper.document.'body'.p.each { p ->
println "Got paragraph: ${p.text()}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment