Hi,
I need help for convert HTML content to RTF format, I use RTFEditorKit Java Class and HTMLEditorKit Java Class for convert RTF file to HTML format and the insert into ckeditor, this works...but
Now I want save the file in RTF format, I try this viewtopic.php?f=6&t=12579
but not works.
For convert RTF to HTML (Good)
public void onClick$copiarRTF() { String ruta = Sessions.getCurrent().getWebApp() .getRealPath("js\\trafico.rtf"); File file = new File(ruta); FileInputStream fi; try { fi = new FileInputStream(file); StringWriter writer = new StringWriter(); RTFEditorKit rtf = new RTFEditorKit(); HTMLEditorKit html = new HTMLEditorKit(); Document docTemp = rtf.createDefaultDocument(); rtf.read(fi, docTemp, 0);// origen/destino/posicion html.write(writer, docTemp, 0, docTemp.getLength()); fi.close(); String contenido = writer.toString(); //System.out.println(contenido); ckeditor.setValue(contenido.toString()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (BadLocationException e) { e.printStackTrace(); } }
HTML to RTF (Heeeeeeeelp!!)

First try: This example ignore <br/>
public void onClick$copiarHTML() { String contenido = ckeditor.getValue(); //System.out.println(contenido); StringReader reader = new StringReader(contenido); String ruta = Sessions.getCurrent().getWebApp() .getRealPath("js\\trafico.rtf"); File file = new File(ruta); RTFWriter rtfW = new RTFWriter(docTemp); OutputStream os; RTFEditorKit rtf = new RTFEditorKit(); HTMLEditorKit html = new HTMLEditorKit(); Document docTemp = html.createDefaultDocument(); try { html.read(reader, docTemp, 0); os = new BufferedOutputStream(new FileOutputStream(file)); rtf.write(os, docTemp, 0, docTemp.getLength()); } catch (IOException e) { e.printStackTrace(); } catch (BadLocationException e) { e.printStackTrace(); } }
I don't know how preserve <br/>...then I try this:
HTML to RTF (
)
public void onClick$copiarHTML() { //Generales: ruta del fichero y el fichero en sí..eso si existe... //TODO: filtrar, buscar el nombre String nom =Sessions.getCurrent().getWebApp() .getRealPath("js\\nou.rtf"); File nou = new File(nom); //1.Coger el contenido del ckeditor String contenido = ckeditor.getValue(); //2.Meterlo en un documento del tipo HTML //2.1 crear documento HTMLEditorKit htmlK = new HTMLEditorKit(); Document docTemp = htmlK.createDefaultDocument(); //2.2 Volcar contenido //el método read necesita un inputStream o un reader Reader fuente = new StringReader(contenido); try { htmlK.read(fuente, docTemp, 0); // System.out.println(docTemp.getText(0, docTemp.getLength()-1)); //con esto hemos metido el contenido de fuente en el documento temporal fuente.close(); } catch (IOException e1) { e1.printStackTrace(); } catch (BadLocationException e1) { e1.printStackTrace(); } //3.Escribir en formato RTF //Lo he intentado con Output, con writer...y nada, no funciona OutputStream os = null; Writer w = null; try { w = new FileWriter(nou); os = new BufferedOutputStream(new FileOutputStream(nou)); } catch (IOException e2) { e2.printStackTrace(); } OutputStream outS = null; RTFEditorKit rtf = new RTFEditorKit(); try { outS = new DataOutputStream(new FileOutputStream(nou)); //FileOutputStream fo = new FileOutputStream(nom); rtf.write(os, docTemp, 0, docTemp.getLength()); // no funciona rtf.write(outS, docTemp, 0, docTemp.getLength());//no funciona //cerramos todo outS.close(); os.close(); w.close(); } catch (IOException e) { e.printStackTrace(); } catch (BadLocationException e) { e.printStackTrace(); } }
I'm tired of trying things and nothing works, someone comes up with a solution?
there isn't ckeditor plugin with this functionality?
I need help please, thanks!
Hideko,
Hideko,
Substitute <br> by \line - this is the line breaking command in RTF internal code.