0

Using this coding html only will be extracted. but i need to extract the image from rtf. i think the problem is in RTFEditorKit. please suggest your ideas to solve this.

private static String rtfToHtml(Reader rtf) throws IOException {
        JEditorPane p = new JEditorPane();
        p.setContentType("text/rtf");
        RTFEditorKit kitRtf = (RTFEditorKit) 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;
  }

1 Answers1

0

Standard RTFEditorKit does not support images. You can use alternative AdvancedRTFEditorKit. Read the Document and go through all the Character Elements checking their attributes to get images.

StanislavL
  • 56,971
  • 9
  • 68
  • 98