i'm using RTFEditorKit and HTMLEditorKit to convert rtf to html so i can edit using FCKeditor, when i convert from rtf to html is ok but when i submit and convert html to rtf there is this problem the new rtf file doesn't have paragraphs and break lines.
Who can help me with that?
sorry about my english... i'm from Brazil
----------------------------------------------------------------------------------------------------------------------------------------
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);
}
}
----------------------------------------------------------------------------------------------------------------------------------------
Who can help me with that?
sorry about my english... i'm from Brazil
----------------------------------------------------------------------------------------------------------------------------------------
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);
}
}
----------------------------------------------------------------------------------------------------------------------------------------
Re: RTF to HTML and HTML to RTF, with FCKEditor
Re: RTF to HTML and HTML to RTF, with FCKEditor
make sure that the HTML you convert to RTF has the format you expect. If it has the required format and the conversion still fails, it's probably the fault of RTFEditorKit.
If may open RTF in the editor since it's plain text but the editor is not aware of RTF at all.
This seems to be out of the scope of the FCKeditor.
Re: RTF to HTML and HTML to RTF, with FCKEditor
but if i try to open my html with firefox or IE, it's ok.
when i convert HTML to RTF this new file doesn't be like the original.
if i try to convert a normal HTML not converted from a RTF, it does the same thing.
Re: RTF to HTML and HTML to RTF, with FCKEditor
Hmm, if the converter does not preserve line breaks, it's a bug in the RTF package.
Try the following, write a basic main method and call it with simple HTML code which you know for sure that the conversion will fail in any direction. In this way you make sure that the RTF package might be faulty. If it is so, this is has nothing more to do with the editor. If yes, provide me a sample maven project or a sample eclispe dynamic web project and I will check it.
Re: RTF to HTML and HTML to RTF, with FCKEditor
Thanks.
Re: RTF to HTML and HTML to RTF, with FCKEditor
can you share how you accomplished this...