2015-10-27 79 views
0

我正在尋找將RTF字符串轉換爲純文本的方式,但不幸的是我找不到解決方案。如何將rft字符串轉換爲java中的純文本?

我需要這個RTF字符串轉換爲純文本

{\ RTF1 \ ANSI \ ansicpg932 \ deff0 \ deflang1033 \ deflangfe1041 {\ fonttbl {\ F0 \ fnil \ fcharset128 \ '82 \'6C \ '82 \ '72 \ '96 \ '是\ '92 \' A9;} {\ F1 \ fnil \ fcharset128 MS UI 哥特;}} {\ colortbl; \ red0 \ green128 \ blue128;} \ viewkind4 \ UC1 \ PARD \ CF1 \ lang1041 \ b \ F0 \ FS24 \ '83 \ '65 \ '83 \ '58 \ '83 \ '67 \ '82 \ 'C5 \ '82 \' B7 \ '81 \ '42 \」 83 \ '65 \ '83 \ '58 \ '83 \ '67 \ '82 \'c5 \ '82 \'b7 \ '81 \ '42 \ cf0 \ b0 \ f1 \ fs20 \ par \ cf1 \ b \ F0 \ FS24 \ '83 \ '65 \ '83 \ '58 \ '83 \ '67 \ '82 \ 'C5 \ '82 \' B7 \ '81 \ '42 \ CF0 \ B0 \ F1 \ FS20 \帕 \ CF1 \ b \ F0 \ FS24 \ '83 \ '65 \ '83 \ '58 \ '83 \ '67 \ '82 \ 'C5 \ '82 \' B7 \ '81 \ '42 \ CF0 \ B0 \ F1 \ FS20 \帕 \ CF1 \ B \ F0 \ FS24 \ '83 \ '65 \ '83 \ '58 \ '83 \ '67 \ '82 \ 'C5 \ '82 \' B7 \ '81 \ '42 \ CF0 \ B0 \ F1 \ FS20 \帕 \ CF1 \ b \ F0 \ FS24 \ '83 \ '65 \ '83 \ '58 \ '83 \ '67 \ '82 \'C5 \ 82 \'b7 \ '81 \ '42 \ cf0 \ b0 \ f1 \ fs20 \ par \ cf1 \ b \ f0 \ fs24 \ '83 \ '65 \ '83 \ '58 \ '83 \ '67 \ '82 \ 'C5 \ '82 \' B7 \ '81 \ '42 \ CF0 \ B0 \ F1 \ FS20 \帕 \ CF1 \ b \ F0 \ FS24 \ '83 \ '65 \ '83 \ '58 \」 83 \ '67 \ '82 \ 'C5 \ '82 \' B7 \ '81 \ '42 \ CF0 \ B0 \ F1 \ FS20 \相提並論 \相提並論}

你可以幫我嗎?

+0

@Florian Schaetz:謝謝你的回答,我也發現了這個鏈接,但它似乎提供了一個C#解決方案ñ:( –

回答

0

這是一個位的代碼,我寫了一個項目,必須做類似的事情。你必須測試它是否有效,因爲RTF相對比較深奧,並且webkit翻譯器很難完成。但它經常完成工作。

我希望它適合你。

private static String useWebKitToConvertRtfToPlaintext(String rtf) throws IOException { 
    StringReader rtfReader = new StringReader(rtf); 
    JEditorPane p = new JEditorPane(); 
    p.setContentType("text/rtf"); 
    RTFEditorKit kitRtf = new RTFEditorKit(); 
    try { 
     kitRtf.read(rtfReader, p.getDocument(), 0); 
     EditorKit plainKit = p.getEditorKitForContentType("text/plain"); 

     Writer writer = new StringWriter(); 
     plainKit.write(writer, p.getDocument(), 0, p.getDocument().getLength()); 
     String out = writer.toString(); 
     return out; 
    } catch (BadLocationException e) { 
     e.printStackTrace(); 
    } 

    return null; 
} 
+0

感謝您對幫扶,倒黴的我:(它輸出值「ƒeƒXƒg,Å,·ЃBƒeƒXƒg,Å,·ЃB ƒeƒXƒg,Å,·ЃB ƒeƒXƒg,Å,·ЃB ƒeƒXƒg,Å,·ЃB ƒeƒXƒg,Å,·ЃB ƒeƒXƒg,Å,·ЃB ƒeƒXƒg,Å,·ЃB」 似乎不正確編碼:( –

相關問題