How To Convert rtf To String In Java?

3.44K viewsErrorJava
0

How To Convert rtf To String In Java?

Manohar Changed status to publish October 8, 2019
Add a Comment
0
public String convertRtfToText(String fareRules) throws IOException, BadLocationException {
		
		try {
			byte[] x = Base64.getDecoder().decode(fareRules.getBytes());
			RTFEditorKit rtfParser = new RTFEditorKit();
			Document document = rtfParser.createDefaultDocument();
			rtfParser.read(new ByteArrayInputStream(x), document, 0);
			String fareRuleText = document.getText(0, document.getLength());
			return fareRuleText;
			
		} catch (Exception e) {
			//here write logs
			
		}
		return fareRules;

	}

Use above code ,hope it will work.

Manohar Changed status to publish October 8, 2019
Add a Comment
Write your answer.