@office-open/rtf
v0.15.1
Published
Generate and parse Rich Text Format documents with office-open DocumentOptions — no Microsoft Office required
Maintainers
Readme
@office-open/rtf
Generate and parse Rich Text Format (RTF) documents with plain
DocumentOptionsJSON — no Microsoft Office required.
Features
- ✍️ Rich Text — Parse text runs, character formatting, fonts, colors, Unicode, and hexadecimal escapes
- 📑 Paragraphs — Read alignment, spacing, indentation, tabs, borders, and shading
- 📊 Tables — Read flat and nested table structure and cell formatting
- 🎨 Styles — Read character, paragraph, and table style definitions
- 📋 Lists — Read numbering definitions, list levels, and overrides
- 🖼️ Shapes — Capture embedded shape instructions
- 🔗 Hyperlinks — Read field-based and direct hyperlinks
- 📝 Fields & Metadata — Read fields, titles, subjects, authors, keywords, dates, and categories
- 📃 Sections — Read page geometry, headers, and footers
- ✍️ Rich Text Writer — Generate RTF text, formatting, tables, fields, pictures, and shapes
Installation
# pnpm
pnpm add @office-open/rtf
# npm
npm install @office-open/rtf
# yarn
yarn add @office-open/rtf
# bun
bun add @office-open/rtfQuick Start
import { generateDocument, parseDocument } from "@office-open/rtf";
import { readFileSync } from "node:fs";
const options = parseDocument(readFileSync("input.rtf", "utf8"));
const rtf = new TextDecoder().decode(generateDocument(options));API
parseDocument(source, options?)— read RTF source intoDocumentOptionsgenerateDocument(options)— write canonicalDocumentOptionsto RTF bytespatchDocument({ data, commands })— parse an RTF file, apply ordered canonical edits, and regenerate itRtfParseError— thrown for malformed RTFRtfGenerateError— thrown for canonical fields that have no RTF representation
Errors and Limitations
- Malformed RTF throws
RtfParseError. - Generation rejects fields that cannot be represented in RTF with
RtfGenerateError; it does not drop them silently. - Patching is a canonical edit and regeneration, not a byte-preserving RTF rewrite.
- Starred unsupported destinations are skipped; non-starred unsupported destinations throw
RtfParseError.
Documentation
- Documentation — additional format guides and examples
- Report Issues — bug reports and feature requests
Related Packages
- office-open — all formats + CLI + AI SDK tools in one install
- @office-open/docx — Word (.docx) generation and parsing
- @office-open/doc — legacy Word (.doc) parsing
- @office-open/odt — OpenDocument Text generation and parsing
