How To Convert rtf To String In Java?

1.85K viewsErrorJava
0

How To Convert rtf To String In Java?

Changed status to publish
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.

Changed status to publish
Add a Comment
Write your answer.