RTF to HTML and HTML to RTF, com FCKEditor

4 respostas
luiscolling

Eu estou usando RTFEditorKit e HTMLEditorKit para converter rtf to html pra usar no FCKeditor, quando eu converto de rtf pra html tudo certo aparentemente, olho o arquivo html e vejo a mesma coisa que no rtf. Mas quando converto de html para rtf ele perde as quebras de linha e os paragrafos, a fonte, cor, tamanho funciona.

Então quem ai pode me ajudar?


Rtf2html file

public static String convertFileStringRTF2HTML(String pathFileSource) {

StringWriter writer = new StringWriter();

try {

File file = new File(pathFileSource);

FileInputStream fi = new FileInputStream(file);

RTFEditorKit rtfEditorKit = new RTFEditorKit();

HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

Document doc = rtfEditorKit.createDefaultDocument();

rtfEditorKit.read(fi, doc, 0);

htmlEditorKit.write(writer, doc, 0, doc.getLength());

fi.close();

} catch (Exception ex) {

Logger.getLogger(Rtf2Html.class.getName()).log(Level.SEVERE, null, ex);

}

return writer.toString();

html2rtf file

public static void convertStringToFileHTML2RTF(String text, String destino) {

StringReader reader = new StringReader(text);

StringWriter writer = new StringWriter();

RTFEditorKit rtfEditorKit = new RTFEditorKit();

HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

Document html = htmlEditorKit.createDefaultDocument();

try {

htmlEditorKit.read(reader, html, 0);
FileOutputStream fo = new FileOutputStream(destino);

rtfEditorKit.write(fo, html, 0, html.getLength());

System.out.println(criou o arquivo supostamente);

fo.close();

} catch (IOException ex) {
Logger.getLogger(Html2Rtf.class.getName()).log(Level.SEVERE, null, ex);
} catch (BadLocationException ex) {
Logger.getLogger(Html2Rtf.class.getName()).log(Level.SEVERE, null, ex);
}
}

4 Respostas

luiscolling

Alguem???

eu não acredito que ninguem tenha convertido RTF pra HTML e HTML pra RTF ??

alguma dica???

B

não precisa insistir, se alguém estiver interessado vai responder.

experimente trocar a linha

StringReader reader = new StringReader(text);

por

StringReader reader = new StringReader("<html><body>A<br/>B<br>C<br/> <p>X</p><p>Y<p>Z</p>1\n 2\n 3</body></html>");

qual a saída do código acima(as quebras de linha)?

pode ser que as quebras de linha
precisem ser fechadas utilizando
. Ou simplesmente no código html estão quebrando linha sem usar as tags html.

luiscolling

opa, valeu por resonder.

fiz o que vc disse a saida no arquivo rtf fica assim:
A B C XYZ1 2 3

tudo na mesma linha.

Acho que o HTMLEditorKit e RTFEditorKit não fazem direito.

Alguma outra idéia?

luiscolling

Andei procurando e achei uma alternativa, usando o openoffice e jdconverter.

Criado 8 de janeiro de 2009
Ultima resposta 12 de jan. de 2009
Respostas 4
Participantes 2