Bonjour,

Débutant en java, je dois dans le cadre d'une application à partir d'un texte saisie par l'utilisateur dans un textRich (donc en html) en un fichier RTF.

J'ai tenter ma chance avec le code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
private String htmlToRtf(Reader html) throws IOException {
		JEditorPane p = new JEditorPane();
		p.setContentType("text/rtf");
		EditorKit kitHtml = p.getEditorKitForContentType("text/html");
		try {
			kitHtml.read(html, p.getDocument(), 0);
			kitHtml = null;
			EditorKit kitRtf = p.getEditorKitForContentType("text/rtf");
			Writer writer = new StringWriter();
			kitRtf.write(writer, p.getDocument(), 0, p.getDocument().getLength());
			return writer.toString();
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
		return null;
	}
mais je me retrouve avec une erreur d'encodage "RTF is an 8-bit format"

Si quelqu'un à une solution, je suis preneur.