RTF libraries
Most RTF libraries do one of two things: extract plain text (strip the markup) or convert RTF to HTML. Full-fidelity RTF reading and writing lives in word processors (LibreOffice, Word) rather than in libraries; for that, convert with soffice --headless --convert-to docx and use a DOCX library.
| Language | Library | Read | Write | Notes |
|---|---|---|---|---|
| C# | RtfPipe | yes (to HTML) | no | RTF to HTML with tables, lists, pictures, Outlook HTML de-encapsulation |
| Java | RTFEditorKit | yes | yes | built into the JDK (Swing), basic formatting only |
| Java | RTF Parser Kit | yes | no | event parser with full encoding handling, text extraction |
| Python | striprtf | yes (to text) | no | small, pure Python text extraction |
| Ruby | ruby-rtf | yes | no | parses into formatted sections, fonts, colors, tables |
| Rust | rtf-parser | yes | no | lexer + parser into styled blocks, no dependencies |
| PHP | PHPWord | yes (basic) | yes | Word/ODT/RTF document library; writes RTF from an object model |
Not covered by a page: for C and C++ there’s no maintained RTF library (GNU unrtf is a command line converter); in Go, small packages such as github.com/attilabuti/striprtf extract text but have few users; in .NET on Windows, the WinForms RichTextBox control loads RTF and exposes .Text.
By language#
- RTF libraries for C# Convert RTF to HTML in C# and .NET with RtfPipe, with notes on extracting plain text from RTF on Windows.
- RTF libraries for Java Read and write RTF in Java with the JDK's RTFEditorKit and extract text with RTF Parser Kit. Comparison and code examples.
- RTF libraries for Python Extract text from RTF files in Python with striprtf, with notes on other RTF tools for Python.
- RTF libraries for Ruby Parse RTF documents in Ruby with ruby-rtf: text, formatting, fonts, colors and tables. Code examples.
- RTF libraries for Rust Parse RTF documents in Rust with rtf-parser: lexer and parser into styled text blocks, plain text extraction. Code examples.
- RTF libraries for PHP Read and write RTF in PHP with PHPWord: create RTF documents from an object model and convert RTF to DOCX or HTML. Code examples.