Java Swing RTF rtfToPlain(String rtf)

Here you can find the source of rtfToPlain(String rtf)

Description

rtf To Plain

License

Open Source License

Declaration

public static String rtfToPlain(String rtf) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayInputStream;

import javax.swing.text.Document;

import javax.swing.text.rtf.RTFEditorKit;

public class Main {
    public static String rtfToPlain(String rtf) {
        RTFEditorKit rtfParser = new RTFEditorKit();
        Document document = rtfParser.createDefaultDocument();
        try {//from ww  w.  j a va2 s.c  om
            rtfParser.read(new ByteArrayInputStream(rtf.getBytes()), document, 0);
            return document.getText(0, document.getLength());
        } catch (Exception e) {
            throw new RuntimeException("Error converting RTF to plain text", e);
        }
    }
}

Related

  1. RTF2TXT(String Str)