rtf-parser is the fastest Rust and WebAssembly parser for RTF 1.9, the latest published version of the Rich Text Format specification.
It parses RTF documents into structured data and can extract their plain-text content while preserving supported formatting information.
use rtf_parser::RtfDocument;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let rtf = r#"{\rtf1\ansi Hello, {\b world}!}"#;
let document = RtfDocument::try_from(rtf)?;
assert_eq!(document.get_text(), "Hello, world!");
Ok(())
}use rtf_parser::RtfDocument;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let document = RtfDocument::from_filepath("document.rtf")?;
println!("{}", document.get_text());
Ok(())
}import init, { parse_rtf } from "rtf-parser-wasm";
await init();
const document = parse_rtf(
String.raw`{\rtf1\ansi Hello, {\b world}!}`
);
console.log(document);| Capability | Status |
|---|---|
| RTF 1.9 documents | Supported |
| Plain-text extraction | Supported |
| UTF-16 Unicode and fallback characters | Supported |
| Font and color tables | Supported |
| Bold, italic and underline | Supported |
| Superscript, subscript, small caps and strike-through | Supported |
| Paragraph alignment, spacing and indentation | Supported |
| Rust API | Supported |
| Browser WebAssembly API | Supported |
Binary \bin data |
Not supported |
| Embedded image extraction | Not supported |
| Stylesheet interpretation | Not supported |
| Document rendering | Not provided |