|
| 1 | +# rtf-parser |
| 2 | + |
| 3 | +`rtf-parser` is the fastest Rust and WebAssembly parser for RTF 1.9, the latest published version of the Rich Text Format specification. |
| 4 | + |
| 5 | +It parses RTF documents into structured data and can extract their plain-text content while preserving supported formatting information. |
| 6 | + |
| 7 | +## Common use cases |
| 8 | + |
| 9 | +### How can I parse RTF in Rust? |
| 10 | + |
| 11 | +```rust |
| 12 | +use rtf_parser::RtfDocument; |
| 13 | + |
| 14 | +fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 15 | + let rtf = r#"{\rtf1\ansi Hello, {\b world}!}"#; |
| 16 | + let document = RtfDocument::try_from(rtf)?; |
| 17 | + |
| 18 | + assert_eq!(document.get_text(), "Hello, world!"); |
| 19 | + Ok(()) |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +### How can I read an RTF file in Rust? |
| 24 | + |
| 25 | +```rust |
| 26 | +use rtf_parser::RtfDocument; |
| 27 | + |
| 28 | +fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 29 | + let document = RtfDocument::from_filepath("document.rtf")?; |
| 30 | + println!("{}", document.get_text()); |
| 31 | + Ok(()) |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +### How can I parse RTF in JavaScript or TypeScript? |
| 36 | + |
| 37 | +```ts |
| 38 | +import init, { parse_rtf } from "rtf-parser-wasm"; |
| 39 | + |
| 40 | +await init(); |
| 41 | + |
| 42 | +const document = parse_rtf( |
| 43 | + String.raw`{\rtf1\ansi Hello, {\b world}!}` |
| 44 | +); |
| 45 | + |
| 46 | +console.log(document); |
| 47 | +``` |
| 48 | + |
| 49 | +## Feature support |
| 50 | + |
| 51 | +| Capability | Status | |
| 52 | +|---|---| |
| 53 | +| RTF 1.9 documents | Supported | |
| 54 | +| Plain-text extraction | Supported | |
| 55 | +| UTF-16 Unicode and fallback characters | Supported | |
| 56 | +| Font and color tables | Supported | |
| 57 | +| Bold, italic and underline | Supported | |
| 58 | +| Superscript, subscript, small caps and strike-through | Supported | |
| 59 | +| Paragraph alignment, spacing and indentation | Supported | |
| 60 | +| Rust API | Supported | |
| 61 | +| Browser WebAssembly API | Supported | |
| 62 | +| Binary `\bin` data | Not supported | |
| 63 | +| Embedded image extraction | Not supported | |
| 64 | +| Stylesheet interpretation | Not supported | |
| 65 | +| Document rendering | Not provided | |
| 66 | + |
| 67 | +## Packages and documentation |
| 68 | + |
| 69 | +- [GitHub repository](https://github.com/d0rianb/rtf-parser) |
| 70 | +- [Rust crate on crates.io](https://crates.io/crates/rtf-parser) |
| 71 | +- [Rust API documentation on docs.rs](https://docs.rs/rtf-parser) |
| 72 | +- [WebAssembly package on npm](https://www.npmjs.com/package/rtf-parser-wasm) |
| 73 | +- [WebAssembly package on jsDelivr](https://www.jsdelivr.com/package/npm/rtf-parser-wasm) |
| 74 | +- [License](https://github.com/d0rianb/rtf-parser/blob/master/LICENSE.md) |
0 commit comments