I need to convert HTML to RTF, and I am using this code:
private static String convertToRTF(String htmlStr) {
OutputStream os = new ByteArrayOutputStream();
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
RTFEditorKit rtfEditorKit = new RTFEditorKit();
String rtfStr = null;
htmlStr = htmlStr.replaceAll("", "#NEW_LINE#");
htmlStr = htmlStr.replaceAll("
", "#NEW_LINE#");htmlStr = htmlStr.replaceAll("
", "");InputStream is = new ByteArrayInputStream(htmlStr.getBytes());
try {
Document doc = htmlEditorKit.createDefaultDocument();
htmlEditorKit.read(is, doc, 0);
rtfEditorKit.write(os, doc, 0, doc.getLength());
rtfStr = os.toString();
rtfStr = rtfStr.replaceAll("#NEW_LINE#", "\\\\par ");
} catch (IOException e) {
e.printStackTrace();
} catch (BadLocationException e) {
e.printStackTrace();
}
return rtfStr;
}
The problem is when I try to convert HTML that had bullets or numbers like this:
one
two
This is the HTML:
- one
- two
And this the convert result:
onetwo
RTF:
{\rtf1\ansi
{\fonttbl\f0\fnil Monospaced;\f1\fnil 'Segoe UI';}
\par
\f1 one\f1 two\par \par
}
How can I convert the numbers and bullets?