Click here to Skip to main content
16,017,488 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i need to convert rtf file to xml file.
The xml file will contain, if the text in rtf file is bold then we have to specify the bold in xml file.
The requerements same as bold and it has to check 2.italic
3.alignment
4.paragraphs
5.spacing

What I have tried:

i tried to convert rtf to text but i didn't find any jar file for rtfToHtml method

Java
String rtfText;
			String rtfToHtml(Reader rtf) {
		    JEditorPane p = new JEditorPane();
		    p.setContentType("text/rtf");
		    String htmlText = rtfToHtml(new FileReader(new File("myfile.rtf")));
		    EditorKit kitRtf = p.getEditorKitForContentType("text/rtf");
		    try {
		        kitRtf.read(rtf, p.getDocument(), 0);
		        kitRtf = null;
		        EditorKit kitHtml = p.getEditorKitForContentType("text/html");
		        Writer writer = new StringWriter();
		        kitHtml.write(writer, p.getDocument(), 0, p.getDocument().getLength());
		        return writer.toString();
		    } catch (BadLocationException e) {
		        e.printStackTrace();
		    }
		    return null;
		}
Posted
Updated 28-Apr-16 0:29am
v4
Comments
Garth J Lancaster 18-Apr-16 2:27am    
well,

a) you dont provide any code, so its hard for us to see what you've done - as a wise old man once said to me, if its in your head and not on paper, its fantasy, and its hard to assist with a blank piece of paper

b) you dont provide us with any examples of the rtf and what you expect to see as XML
Sergey Alexandrovich Kryukov 18-Apr-16 3:17am    
What does it mean, "bold in XML file"? :-)
The question does not seem to make any sеnse.
—SA
Member 12466896 18-Apr-16 4:37am    
If we have bold text in rtf file, we have to mention in xml file within <bold>bold text tags.If the title is center aligned we have to represent the text as<center-aligned>center aligned text tags
Member 12466896 18-Apr-16 4:39am    
if we have paragraph then we have to surround the paragraph text within paragraph tags

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900