Rich Text Format
Rich Text Format (RTF) is a proprietary document file format, first published by Microsoft Corporation in 1987, designed to enable the cross-platform interchange of text and graphics with rich formatting capabilities, such as fonts, colors, paragraphs, tables, and embedded images, across different word processing applications and operating systems.[1][2] The format employs a plain-text syntax consisting of control words (e.g., \b for bold), control symbols, and grouped structures enclosed in braces to define formatting instructions, making RTF files human-readable and editable in a text editor while preserving layout and style information.[3][4]
Originally developed to facilitate document exchange between Microsoft Word on Windows and Macintosh systems, RTF addressed the limitations of plain text by supporting advanced features like character styles, headers, footers, and hyperlinks in later iterations, without relying on platform-specific binary code.[5] Microsoft released multiple specification versions between 1992 and 2008, culminating in version 1.9.1, which expanded support for Unicode, complex scripts, and multimedia elements to accommodate evolving software capabilities.[2][6] Despite its proprietary nature, the published specifications allowed third-party implementations, leading to broad adoption in applications like email clients (e.g., Outlook's RTF mode for internal formatting) and help systems (e.g., WinHelp), though its use has diminished with the prevalence of more versatile formats like HTML, PDF, and Office Open XML due to RTF's growing complexity and limited extensibility for modern web standards.[2][1] RTF remains notable for its role in early digital document portability and as a bridge between proprietary ecosystems, with ongoing support in legacy systems and niche tools for its simplicity in parsing formatted content.[7]
Historical Development
Origins in Microsoft Word
The Rich Text Format (RTF) originated in 1987 as a proprietary document interchange standard developed by Microsoft for its Word word processor.[2] It was created by three programmers on the Microsoft Word development team to address compatibility challenges in exchanging formatted documents between platforms, particularly the Macintosh and Windows versions of Word, which relied on incompatible binary formats.[8] RTF employed a plain-text structure with markup via backslash-prefixed control words, enabling basic formatting like bold, italics, and fonts to be preserved without embedding platform-specific binaries.[1]
The format debuted with Microsoft Word 3.0 for Macintosh that year, marking its initial implementation as an export and import mechanism for cross-application and cross-platform transfer.[9] An early technical description appeared in the March 1987 issue of the Microsoft Systems Journal, outlining RTF as a method to standardize text transfer between diverse word processing systems while supporting rich formatting elements beyond plain ASCII.[2] This approach prioritized portability over full fidelity to Word's native capabilities, focusing on core attributes such as character styles and simple layout to facilitate interoperability in an era of fragmented software ecosystems.[10]
Microsoft's motivation stemmed from practical needs during Word's expansion: the Mac version, released in 1985, and the Windows version in 1989 required a neutral intermediary to avoid vendor lock-in and enable data sharing with competitors' tools.[8] Unlike Word's evolving binary files, RTF's text-based design allowed human readability and editability with basic tools, though it sacrificed efficiency for universality.[1] The initial specification, while not formally versioned until 1.0 in 1992, laid the groundwork for RTF's role as a bridge format, influencing subsequent word processing standards.[2]
Version Evolution and Standardization Efforts
The Rich Text Format (RTF) specification evolved through a series of incremental updates by Microsoft, primarily to accommodate new features introduced in successive versions of Microsoft Word and to enhance cross-application interoperability. Initially introduced in 1987 as a proprietary interchange format, the first formal specification document, version 1.0, was published in 1992.[2][1] Subsequent revisions in the 1.x series addressed expanding requirements, such as improved support for character encodings, graphics embedding, and advanced formatting; notable releases include version 1.5, which incorporated control words from Microsoft Word 95 (version 7.0) and Word 97, and version 1.6 in May 1999.[3][4] These updates maintained backward compatibility where possible while extending the format's scope, with minor versions often tied to specific Word releases to ensure fidelity in document export and import.[2]
The specification culminated in version 1.9.1, released on March 20, 2008, which implemented capabilities aligned with Microsoft Office 2007, including enhanced handling of tables, lists, and Unicode support.[6][2] This release, documented in a comprehensive 12 MB specification, represented the final major iteration, as Microsoft has not issued subsequent versions despite ongoing use in products like Exchange Server protocols.[11] Post-2008, RTF extensions have appeared in specialized contexts, such as email encoding algorithms, but without altering the core format.[12]
Standardization efforts for RTF have been limited to Microsoft's unilateral publication of specifications, without adoption by international bodies like ISO or ECMA International. Unlike Microsoft's later Office Open XML (standardized as ECMA-376 and ISO/IEC 29500), RTF remained a de facto standard controlled by Microsoft, with public specifications enabling third-party implementations since the early 1990s.[2] The 2008 release of version 1.9.1 fell under Microsoft's Open Specifications Promise, which grants royalty-free rights to implement the format, reducing barriers to adoption but not conferring formal open-standard status.[13] This approach prioritized practical interchange over rigorous consensus-driven standardization, reflecting RTF's origins as a Microsoft-centric solution for proprietary word processing compatibility.[1]
Technical Specifications
Core Syntax and Control Words
The core syntax of Rich Text Format (RTF) comprises unformatted text interspersed with control words, control symbols, and groups delimited by braces, enabling the encoding of formatted documents in a plain-text structure compatible with 7-bit ASCII for transport.[3] This syntax, first formalized in Microsoft's RTF version 1.0 in 1987 and refined through subsequent versions up to 1.9.1 in 2008, prioritizes human readability and parser simplicity, with control sequences ignored by readers if unrecognized to ensure forward compatibility.[3][14]
Control words form the primary mechanism for specifying formatting and structure, consisting of a backslash (\) followed by a sequence of 1 to 32 lowercase alphabetic characters (case-sensitive), terminated by a delimiter such as a space, non-alphanumeric character, or a digit/hyphen indicating a numeric parameter.[3][15] Parameters, when present, are signed integers typically ranging from -32767 to 32767; for toggle-style words (e.g., enabling/disabling attributes), omission defaults to 1 (on), while explicit 0 turns the feature off.[3] Examples include \b to activate bold formatting and \b0 to deactivate it, or \fs20 to set font size to 10 points (20 half-points).[3]
Control symbols provide shorthand for special characters or actions, structured as a backslash immediately followed by a single non-alphabetic character without further delimiters.[3][15] Common instances are \par for a paragraph break, \~ for a non-breaking space, and escapes like \{ or \} to represent literal braces in text.[3]
Groups encapsulate scopes for attributes and content, bounded by matching curly braces { and }, with nesting permitted to hierarchical depths; literal braces within text must be escaped.[3][15] The entire document is typically wrapped in an outer group starting with the version indicator \rtf1 (for RTF version 1), followed by header information like character set declarations (e.g., \ansi) and default font selection (\deff0).[3] Destinations, a subset of control words (e.g., \fonttbl for the font table or \header for document headers), initiate specialized subgroups whose contents define tables, objects, or metadata; newer or optional destinations since 1987 are prefixed with \* (e.g., \*\xmltag) to signal ignorable data for legacy parsers.[3][15]
Basic formatting relies on a core set of control words applied within groups, such as \i for italics, \ul for underlining, \cf1 for selecting color index 1 from the color table, and \qc for centering justification.[3] For instance, the RTF fragment {\b\i Bold italic text}\par renders bold and italicized text followed by a paragraph break, inheriting prior group attributes unless reset by commands like \plain.[3] These elements ensure RTF's extensibility while maintaining a consistent parsing model across applications.[3]
Character Encoding Mechanisms
Rich Text Format (RTF) encodes text characters primarily using escape sequences and control words within its ASCII-based syntax, allowing representation of both standard and extended character sets while maintaining compatibility across applications. The core mechanism relies on a declared default character set, typically ANSI, where printable text is inserted directly as bytes corresponding to the specified code page, and non-standard characters are handled via hexadecimal or Unicode escapes.[3] This approach ensures that RTF files remain portable, as the file itself contains only 7-bit ASCII for structural elements, with character data mapped to local system interpretations via header declarations.[3]
The ANSI character set serves as the default encoding, declared in the document header with the \ansi control word, enabling direct insertion of characters from the 8-bit ANSI range (code points 0-255).[3] To specify the precise code page for ANSI interpretation—such as Windows-1252 (CP1252) for Western European languages—the \ansicpgN control word is used, where N is the decimal code page identifier (e.g., \ansicpg1252); this value guides applications in converting the embedded ANSI bytes to Unicode during reading and informs fallback mappings when generating RTF from Unicode sources.[3][2] Alternative legacy sets include Macintosh (\mac), IBM PC 437 (\pc), and IBM PC 850 (\pca), though ANSI remains predominant for cross-platform use.[3] For characters exceeding the 7-bit ASCII range but within the 8-bit code page, RTF employs hexadecimal notation via 'hh, where hh represents the two-digit hexadecimal value of the byte in the current code page, allowing embedding of accented or symbol characters without altering the file's ASCII structure (e.g., 'A9 for the copyright symbol © in CP1252).[3]
Unicode support, introduced in RTF version 1.5 with Microsoft Word 97, extends encoding to 16-bit characters via the \uN control word, where N is the signed decimal Unicode code point (ranging from -32768 to 32767, with higher values negated for representation, such as \u-12345 for U+CE39).[3] This is typically followed by an optional single-byte ANSI fallback character for backward compatibility with pre-Unicode RTF readers, ensuring graceful degradation; the \ucN control word defines the number of subsequent characters to skip when processing the Unicode sequence (default \uc1 for the fallback).[3] For instance, the Greek Gamma (U+0393) might appear as \u915'G, where 'G' approximates it in ANSI.[3] When a Unicode character lacks an ANSI equivalent under the declared \ansicpg, the \uN mechanism is mandatory, as RTF writers must encode such outliers explicitly rather than substituting bytes.[16] Dual representations for compatibility use \upr groups containing ANSI text alongside \ud subgroups with Unicode variants, scoped within braces to maintain parsing order.[3]
International and bidirectional text handling integrates these mechanisms with font-specific charsets via \fcharsetN (e.g., 0 for ANSI, 77 for Macintosh, 178 for Symbol, or 222 for Arabic), which map Unicode code points to glyph indices in the selected font without altering the core text encoding.[3] Code pages for embedded fonts are denoted by \cpgN, aligning character interpretation with regional standards like CP437 for U.S. IBM systems.[3] Limitations persist for full Unicode coverage, as RTF predates UTF-8 and relies on pairwise ANSI-Unicode fallbacks, potentially leading to information loss in non-Latin scripts unless \u escapes are exhaustively used; applications must thus reference the \ansicpg for accurate rendering.[16][2]
Document Structure and Groups
The document structure of Rich Text Format (RTF) relies on a hierarchical organization of nested groups, each delimited by opening and closing curly braces { and }, which encapsulate control words, symbols, text, and subgroups to scope formatting and content attributes locally. The entire file constitutes a single top-level group that begins immediately with the control word \rtf followed by an integer version number, such as \rtf1 for the base version supporting core features, ensuring parsers recognize the format and its capabilities. This structure, defined in the formal syntax as <file> ::= '{' <header> <document> '}', promotes modularity and prevents global state pollution, with groups pushing current formatting states onto an implicit stack upon entry and restoring them upon exit.[15]
The header precedes any document text and contains resource definitions in dedicated groups, including the mandatory font table introduced by \fonttbl, which enumerates fonts via entries like \f0\froman\fprq2\fcharset0 [Times New Roman](/page/Times_New_Roman);, where \fN assigns an index N, \froman specifies a roman family, and \fcharset0 denotes ANSI encoding for cross-platform reference. Optional groups follow, such as the color table {\colortbl;\red0\green0\blue0;}, defining colors with RGB triplets in the range 0-255 delimited by semicolons for indexed use in highlighting or styles; the stylesheet {\stylesheet{\s0\sa200 [Normal](/page/Normal);}}, listing named styles with indices like \s0 for paragraph defaults including spacing (\sa200 for 200 twips after); and the default font index via \deff0. These header groups must appear before the first plaintext character and are ignored if malformed, prioritizing document readability over strict validation.[15][3]
The document body, succeeding the header, organizes content into one or more sections implicitly starting after header groups or explicitly via \sect, with each section comprising zero or more section formatting controls (e.g., \sectd to reset margins and columns like \margl1440 for 1-inch left margin in twips), optional header/footer subgroups (e.g., {\header\pard\qr Page \chftn {} }), and paragraphs. Paragraphs form the core unit, typically grouped as {\pard\ql\li0 text content\par}, where \pard resets to default alignment and indents, \ql sets left justification, and \par terminates the unit, allowing nesting for inline elements like fields or pictures. Sections can chain via repeated \sect without explicit closure, enabling multi-column layouts (\cols2) or breaks, while tables employ deeply nested groups for rows (\trowd) and cells (\cell), preserving hierarchy for complex layouts. Special destinations, such as footnotes ({\*\footnote\pard\plain\fs20 Reference.\par}) or fields ({\field{\*\fldinst { TIME }}), are prefixed with \* to denote non-displayed groups processed by applications.[15][3]
Nesting depth is theoretically unlimited but practically constrained by parser stacks, with control words like \b (bold on) applying recursively to enclosed text until toggled (\b0) or group end, inheriting outer attributes unless reset (e.g., \plain for character defaults). This brace-delimited grouping, combined with backslash-escaped braces (\{ literal open), ensures unambiguous parsing even in plain-text editors, supporting interoperability across versions since RTF 1.0 in 1987, though later extensions like Unicode via \ucN require careful group isolation to avoid legacy breakage.[15][3]
Core Features
Basic Text Formatting
Basic text formatting in Rich Text Format (RTF) primarily involves character-level attributes applied via control words within curly brace groups { }, which scope the formatting to enclosed text until toggled or reset.[3][15] These controls enable styling such as emphasis, font variations, and positional adjustments, persisting from the point of declaration unless explicitly turned off, with defaults favoring no formatting (e.g., plain text).[3] RTF's syntax ensures portability across applications supporting the format, as defined in specifications from version 1.0 onward.[15]
Key character formatting control words include toggles for emphasis:
- Bold:
\b (on), \b0 (off); applies thickened strokes to characters.[3][15]
- Italic:
\i (on), \i0 (off); slants characters for oblique emphasis.[3][15]
- Underline:
\ul (continuous, on), \ul0 (off); variants include \uld (dotted), \uldb (double), and \ulw (words only).[3][15]
- Strikethrough:
\strike (single line, on), \strike0 (off); draws a horizontal line through characters.[3]
Font-related controls specify typeface and size:
- Font selection:
\fN, where N indexes the document's font table (e.g., \f0 for the default); the font table is defined earlier via \fonttbl.[3][15]
- Font size:
\fsN, where N is half-points (e.g., \fs24 for 12-point text); default is 24 half-points (12 points).[3][15]
Color and positional formatting add visual and layout cues:
- Foreground color:
\cfN, referencing the color table index N (default 0, typically black); color table defined via \colortbl.[3][15]
- Background (highlight) color:
\cbN, similarly indexed.[3]
- Superscript:
\super or \upN (N twips above baseline, default 6 half-points).[3]
- Subscript:
\sub or \dnN (N twips below baseline, default 6 half-points); reset with \nosupersub.[3]
An example RTF snippet for formatted text is {\b{\i Bold italic} normal}, rendering "Bold italic" in bold and italic while reverting to plain for "normal".[15] These features, stable since RTF version 1.0 in 1987, support interoperability but require parsers to handle group nesting correctly for accurate rendering.[3][15]
Rich Text Format (RTF) enables the embedding of complex objects through dedicated object groups, primarily leveraging Object Linking and Embedding (OLE) mechanisms to integrate content from external applications such as spreadsheets, charts, or executables directly into the document structure. The \object control word initiates an object destination, which encompasses properties, data, and a result subgroup for rendering; the \objemb keyword specifies an embedded OLE object, storing its binary data stream within the RTF file, while \objlink denotes a linked object referencing external sources. Embedded objects include attributes like class identifier (\objclass), name (\objname), dimensions (\objw, \objh), and scaling factors (\objscalex, \objscaley), with the result subgroup supporting RTF text (\rsltrtf), pictures (\rsltpict), or bitmaps (\rsltbmp) for display purposes.[3][17]
Media embedding in RTF focuses on images via the \pict destination, which encapsulates binary or hexadecimal-encoded picture data following a blip type declaration; hexadecimal encoding is the default, but binary mode is activated with \bin followed by the data length in bytes. Picture groups include metadata for width (\picw), height (\pich), intended dimensions (\picwgoal, \pichgoal), scaling (\picscalex, \picscaley), and cropping (\piccropt et al.), allowing precise integration into text flow. Support for embedded fonts and vector graphics extends media capabilities, though OLE objects can also serve as containers for pictures in their result subgroups.[3][17]
RTF accommodates various image formats through blip types, with raster and vector support evolving across versions:
| Blip Type | Format Description | Introduction Notes |
|---|
\emfblip | Enhanced Metafile (vector) | RTF 1.5+; scalable graphics |
\jpegblip | JPEG (compressed raster) | Word 97+; lossy compression |
\pngblip | PNG (lossless raster) | Word 97+; supports transparency |
\wmetafile | Windows Metafile (vector) | Core RTF; device-independent |
\wbitmap | Windows Bitmap (raster) | Early RTF; device-dependent |
\dibitmap | Device-Independent Bitmap | Universal raster embedding |
These formats ensure cross-application portability, though rendering fidelity depends on the consuming software's implementation of OLE and blip decoding.[3][17]
Font and Style Management
RTF manages fonts through a dedicated font table group, initiated by the \fonttbl control word, which enumerates available fonts for the document. Each entry in the table is indexed numerically, formatted as \fN \fontname{FontName} where N is the zero-based index and FontName specifies the typeface, such as \f0 \fontname{[Times New Roman](/page/Times_New_Roman)}.[3] This table allows up to 4096 fonts in version 1.5, with optional parameters like \fcharset to define character sets (e.g., ANSI as 0, Symbol as 2) and \fprq for pitch and family (e.g., 0 for default, 1 for fixed, 2 for variable).[3] Font selection in the document body occurs via \fN, switching to the specified index until changed.[15]
Character styles are applied inline using destination-specific control words within the document's main group, toggling attributes on or off. Basic formatting includes \b for bold, \i for italic, and \ul for underline (with variants like \uld for dotted underline), which persist until toggled or reset by \plain, reverting to the default state (no formatting, 12-point font).[](https://www.biblioscape.com/rtf15_spec.htm) Font size is controlled by \fsN, where Nrepresents half-points (e.g.,\fs24for 12 points), applicable after font selection.[](https://www.biblioscape.com/rtf15_spec.htm) Additional attributes encompass\scapsfor small capitals,\superand\subfor superscript/subscript (with size reduction typically to 58% or customizable via\ssemidfor 2/3 height), and\strike` for strikethrough.[15]
Color integration for styles relies on a color table defined by \colortbl, mirroring the font table structure, with entries like \red0\green0\blue0; for black. Text color is set via \cfN, referencing the index N from this table, while highlight (background) uses \highlightN.[3] These mechanisms ensure styles are device-independent, relying on the reader's available fonts and falling back to substitutes if exact matches are unavailable, as specified in the \fnil, \froman, \fswiss, \fmodern, \fscript, or \fdecor family keywords.[15]
The following table summarizes key character formatting control words for font and style management:
| Control Word | Description | Parameter |
|---|
\b | Toggle bold | None (on/off) |
\i | Toggle italic | None (on/off) |
\ul | Toggle underline | None (solid); variants like \ulnone to disable |
\fsN | Set font size | N = half-points (e.g., 24 for 12 pt) |
\cfN | Set foreground color | N = color table index |
\super / \sub | Superscript / subscript | None; resets with \nosupersub |
\plain | Reset all character formatting | None |
These controls operate within nested groups delimited by braces {} for scoped application, preventing global spillover.[3] While RTF emphasizes direct formatting over named styles, version 1.5 introduces limited stylesheet support via \stylesheet, defining reusable paragraph and character styles (e.g., \sN for selection), though adoption remains sparse compared to inline methods due to RTF's origins in word processor interchange.[15]
Advanced Capabilities
Annotations and Hyperlinks
In RTF, annotations serve as a mechanism for embedding comments or notes attached to designated text ranges within a document, functioning similarly to revision marks or footnotes but stored as separate destinations. Each annotation requires a unique identifier provided by the control word \atnid followed by an integer index referencing the revision table, ensuring traceability to an author or source. The actual annotation content is enclosed in a destination group initiated by \annotation, which may include formatted text but requires explicit resets such as \sectd, \pard, and \plain to prevent inheritance of prior formatting attributes. These groups are typically marked with an asterisk (\*) to indicate they are ignored by non-supporting readers.[3]
References to annotations appear inline via control words like \atnstart N to denote the start of the annotated range (where N is the ID), \chatn to insert a visible annotation mark or character, and \atnref N for cross-references, with the range potentially closed by \atnend in some implementations. Optional elements include \atnauthor for the creator's name, \atntime for timestamps, and \atnicn for associated icons, all defined as destinations to maintain document portability. This structure, introduced in early RTF specifications around version 1.2, supports collaborative editing but relies on application-level rendering for visibility, as the core RTF parser treats annotations as non-essential.[3][15]
Hyperlinks in RTF are realized through field destinations rather than dedicated control words, leveraging the \field group to encapsulate dynamic instructions interpretable by supporting applications like word processors. The standard syntax for a hyperlink field is {\field{\*\fldinst HYPERLINK "target"}{\fldrslt display_text}}, where \*\fldinst specifies the HYPERLINK instruction with the target URL or file path enclosed in quotes, and \fldrslt holds the rendered, clickable display text. Backslashes in paths must be escaped by doubling (e.g., C:\\path), and relative links can reference a base URL set via \hlinkbase in the document's information group. This field-based approach, compatible since RTF version 1.5, enables both external web links (e.g., "https://example.com") and internal bookmarks, with attributes like CFE_LINK applied during parsing for underline and color styling in renderers such as Microsoft RichEdit.[3][18]
While effective for interoperability, RTF hyperlinks depend on the consuming application's field evaluation; unevaluated fields display raw instructions, potentially exposing URLs as hidden text marked with CFE_HIDDEN. Security-aware parsers, such as those in modern office suites, may restrict or scan hyperlink targets to mitigate risks like malicious redirects, though RTF's plain-text nature allows inspection absent such protections. Adoption of this syntax aligns with broader field support for macros and calculations, but lacks native support for advanced features like JavaScript handlers found in HTML.[18]
Drawing and Shape Objects
Drawing and shape objects in RTF enable the inclusion of vector graphics, such as lines, rectangles, ellipses, arcs, polylines, polygons, and text boxes, facilitating basic diagramming and illustration within documents. These features were first specified in RTF version 1.2, with significant expansions in version 1.5 to support Microsoft Word 97's drawing capabilities, including properties for positioning, filling, lining, and grouping.[3] Shapes are rendered via embedded picture data, typically in metafile formats, allowing interoperability across applications while maintaining scalability unlike raster images.[17]
The core syntax for shapes employs the \shp destination control word to encapsulate properties, followed by \shppict to reference the graphical content within a \pict group. For instance, positioning is controlled by \posx N (horizontal offset in twips from the anchor) and \posy N (vertical offset), with anchors relative to page margins, columns, or paragraphs via flags like \shpbxpage or \shpbxmargin.[3] Size and scaling use \shpbxignore or explicit width/height parameters, while fill attributes are set through \shpfill with color indices (RGB values 0-255) and patterns via \shpfhdr0 for foreground blending. Line properties include \shpwr N for width in twips, \shpwrk for style (e.g., solid or dashed), and foreground color via \shpfr.[3]
Shape types are designated by parameters within the \shp group, such as simple primitives (rectangles via bounding coordinates, ellipses inscribed in rectangles) or complex forms like polylines defined by point sequences (\dpptx N \dppty N pairs). Text integration occurs in text boxes using \shptxbx with internal margins (\dptxbxmarl, etc.) and paragraph content. Grouping is supported via \shpgroup, enabling hierarchical compositions of multiple shapes treated as a single object for positioning and manipulation.[3] Wrapping behavior around shapes is managed by \shpbylockanchor or text flow controls, ensuring layout flexibility in word processors.[3]
In pre-Word 97 RTF (up to version 1.2), drawing objects used the {\*\do} group with subtypes like \dpline (lines between two points), \dprect (rectangles, optionally rounded with \dproundr), \dpellipse, \dparc (with flip flags for direction), and \dppolyline (with \dppolycount N followed by points). These relied on <dphead> for positioning (\dobxpage, \dobypara) and <dpprops> for rendering attributes, but lacked the extensibility of later \shp implementations, which integrate enhanced metafile (EMF) data for richer effects like gradients and shadows.[3] Compatibility requires parsers to handle both legacy \do and modern \shp formats, as incomplete support can lead to rendering failures in older readers.[4]
rtf
{\shp \posx 1000 \posy 2000 \shptype 1 \shpwr 10 \shpfr 0 \shpfbl 1
\shppict {\pict\emfblip ...}} % Example: positioned [rectangle](/page/Rectangle) with line and fill
{\shp \posx 1000 \posy 2000 \shptype 1 \shpwr 10 \shpfr 0 \shpfbl 1
\shppict {\pict\emfblip ...}} % Example: positioned [rectangle](/page/Rectangle) with line and fill
This structure embeds shapes inline with text, measured in twips (1/1440 inch), promoting precise control but increasing file complexity due to verbose property lists.[3]
Tables and Lists
RTF tables are constructed as sequences of rows, each initiated by the \trowd control word to define row properties and defaults. Cell boundaries within a row are specified using \cellx keywords followed by positions in twips relative to the table's left edge, with gaps between cells controlled by \trgaph. Individual cells contain one or more paragraphs marked by \intbl, terminated by \cell, and the row concludes with \row. Row-level formatting includes alignment options such as \trql for left justification, \trqc for centering, and \trqr for right justification, along with indent positioning via \trleft.[3][15]
Cell-specific attributes support advanced layout, including merging with preceding cells using \clmrg (merge) and \clmgf (first merged cell), vertical alignment via \clvertalt, \clvertalc, or \clvertabt, and borders defined by keywords like \clbrdrt (top), \clbrdrb (bottom), \clbrdrl (left), and \clbrdrr (right), each customizable with styles such as \brdrs for single lines or \brdrth for thick. Shading applies through \clshdng with values in hundredths of a percent, and patterns like horizontal via \clbghoriz. A basic table row example in RTF syntax is:
\trowd\trgaph108\cellx2000\cellx4000
\intbl Cell 1 content.\cell
\intbl Cell 2 content.\cell\row
\trowd\trgaph108\cellx2000\cellx4000
\intbl Cell 1 content.\cell
\intbl Cell 2 content.\cell\row
This structure allows for nested tables and supports up to nine levels of nesting in later RTF versions.[3][15]
Lists in RTF rely on paragraph numbering groups introduced by the \pn destination, which precede numbered or bulleted paragraphs and define auto-generated prefixes. Levels range from 1 to 9 via \pnlvl<N>, with bullets specified by \pnlvlblt using characters like the bullet symbol (Unicode U+2022 or ANSI 149). Numbering formats include decimal (\pndec), lowercase letters (\pnlcltr), uppercase letters (\pnucltr), lowercase Roman (\pnlcrm), and uppercase Roman (\pnucrm), with the prefix text outlined in \pntext and properties like hanging indents via \pnhang or starting values with \pnstart<N>. Indentation adjusts through \pnindent and \pnsp.[3][15]
In RTF versions corresponding to Word 97 and later, lists use override mechanisms with \ls<N> referencing a list style index and \ilvl<N> for the level (0-8), allowing separation of style definitions from paragraph application; the \listtext destination holds the rendered text for the level. An example bulleted list item is:
\pn \pnlvlblt \pntext \bullet\tab Item text.\par
\pn \pnlvlblt \pntext \bullet\tab Item text.\par
This system supports multilevel outlines and restarts numbering per section, though implementation varies by application adherence to the specification.[3][15]
Usage and Interoperability
Primary Applications and Adoption
Rich Text Format (RTF) is primarily employed in word processing applications for creating and editing documents that retain basic formatting such as bold, italics, fonts, and paragraphs during cross-platform exchange. Microsoft WordPad, bundled with Windows since Windows 95, functions as the default editor and viewer for RTF files on Windows systems, supporting features like text alignment, bullet lists, and simple tables up to version 1.9 of the format.[19] Microsoft Word has included RTF import and export capabilities since its early versions, enabling compatibility with non-Microsoft software by converting proprietary .doc files to RTF for interchange.[3]
Open-source alternatives like LibreOffice and Apache OpenOffice also natively support RTF reading and writing, facilitating document portability in diverse environments without licensing restrictions.[20] On macOS, Apple's TextEdit application handles RTF files for basic formatted text editing, underscoring its role in multi-platform workflows. Additional specialized tools, such as the Scrivener writing software, utilize RTF internally for compiling text components into larger projects, leveraging its structured markup for reliable merging.[2]
Adoption of RTF began with its introduction by Microsoft in 1987 as a proprietary yet publicly specified format designed for transferring formatted text and graphics between applications on different operating systems and output devices.[4] Its persistence stems from simplicity and vendor neutrality; by the 1990s, RTF became a de facto standard for email clients embedding formatted messages, as seen in Microsoft Exchange protocols that extend RTF for rich content encapsulation.[12] Despite the rise of XML-based formats like ODF, RTF maintains relevance in legacy systems, government forms (e.g., U.S. court documents available in RTF for universal editing), and conversion pipelines, with Microsoft continuing support through Windows 11 in 2023.[21] Usage peaked in the pre-HTML era for interoperability but has stabilized for niche, low-overhead needs, avoiding the complexity of full office suites.[2]
Rich Text Format (RTF) was developed by Microsoft in 1987 specifically to facilitate cross-platform document interchange, enabling the exchange of formatted text between applications on Windows and Macintosh systems without reliance on platform-specific binaries.[5] Its ASCII-based, human-readable structure supports broad parsing across operating systems, including Windows, macOS, and Linux, where files can be opened by native applications such as WordPad on Windows, TextEdit on macOS, and LibreOffice Writer on Linux.[20][22] This design promotes consistent basic formatting preservation, such as bold, italics, and fonts, making RTF suitable for simple document sharing in heterogeneous environments.[23]
Despite its intent, RTF's cross-platform compatibility encounters limitations due to varying implementation levels among applications and evolving specification versions, which can result in discrepancies like altered font rendering, table layouts, image positioning, or margin handling when documents are transferred between systems.[24] Advanced features, including complex embeddings or proprietary Microsoft extensions in later RTF versions (e.g., up to 1.9.1 as of 2008), may not render identically across all parsers, as non-Microsoft tools often support only core subsets.[25] For instance, embedded images in RTF files generated on Windows integrate binary data directly into the text stream, whereas macOS TextEdit employs the RTFD wrapper—a directory bundle containing RTF plus resource folders—which fails to open as a flat file on Windows or Linux, necessitating conversion tools for interoperability.[26][27]
Open-source applications like AbiWord and LibreOffice enhance compatibility by providing RTF import/export on Linux and other platforms, often achieving higher fidelity for standard features than lightweight viewers, though large files or intricate layouts can strain performance and lead to partial loss of fidelity.[1] Cross-platform libraries, such as those in Python's PyRTF or Java's RTF editors, further mitigate issues by standardizing parsing, but users must verify feature support against the RTF specification to avoid vendor-specific divergences.[28] Overall, while RTF remains viable for basic formatted text portability as of 2025, its reliability diminishes for feature-rich documents compared to modern standards like ODF or HTML, prompting recommendations for testing exchanges in target environments.[29]
UnRTF, a command-line utility developed by the GNU Project, converts Rich Text Format (RTF) documents to HTML, LaTeX, troff macros, plain text, and even RTF itself, supporting versions up to RTF 1.8 with partial handling of later extensions.[30] It processes RTF control words and groups to extract structured content, though complex embedded objects may require additional post-processing.
In Python, the striprtf library strips RTF formatting to yield plain text output, suitable for text extraction from medical or legacy documents stored in RTF.[31] Complementing this, rtfparse builds an in-memory tree structure representing the RTF document's hierarchy, enabling programmatic access to elements like paragraphs, fonts, and tables without full rendering.[32]
For .NET applications, RtfPipe parses RTF streams into HTML, handling control sequences for fonts, colors, and layouts while discarding unsupported features like embedded images in basic mode.[33] Similarly, RtfDomParser, an open-source C# library, generates a document object model (DOM) tree from RTF input, allowing manipulation of text runs, styles, and sections before export to other formats.[34]
JavaScript developers can use rtf-to-html, which leverages an RTF parser to produce complete HTML documents from RTF input, preserving basic styling via CSS equivalents but limited by the parser's scope on advanced RTF groups.[35] For RTF generation, the Apache RTFLib in Java outputs RTF files from structured data, supporting core formatting like bold, italics, and tables for interoperability with word processors.[36]
RTF to PDF conversion often relies on intermediate steps or office suites; for instance, LibreOffice's command-line interface (soffice --convert-to pdf) renders RTF to PDF while interpreting layout controls, though results vary with RTF complexity and version compliance. Open-source libraries like those above typically target text or HTML output, with PDF requiring chained tools such as HTML-to-PDF converters (e.g., via WeasyPrint) for fidelity.
Security Considerations
Parsing Vulnerabilities and Exploits
Rich Text Format (RTF) parsers are susceptible to vulnerabilities arising from the format's verbose and hierarchical structure, which includes nested groups, control words with optional parameters, and support for embedded binary objects, often leading to inadequate input validation, memory corruption, or denial-of-service conditions during deserialization. These issues stem from the difficulty in securely implementing a full RTF parser, as the specification—originally defined by Microsoft in 1987—encompasses hundreds of control sequences that must be processed sequentially, increasing the attack surface for malformed inputs targeting specific parser components like font tables or field codes.[37][38]
In major implementations such as Microsoft Office, parsing flaws have enabled remote code execution (RCE) through heap overflows or uninitialized pointers when handling crafted RTF elements, exploiting failures in bounds checking or pointer arithmetic. For instance, the RTF parser in Microsoft Word's wwlib.dll has been implicated in heap corruption when processing oversized or malformed font tables (\fonttbl), allowing attackers to overwrite memory and execute shellcode after user interaction via file opening. Similar defects occur in paragraph formatting (\pard) or object embedding (\objdata), where excessive nesting or invalid hexadecimal data triggers overflows without proper sanitization.[39][40]
Notable vulnerabilities include those patched in Microsoft Security Bulletins, often rated critical with CVSS scores exceeding 7.8, affecting versions of Word, Outlook, and other Office components that render RTF inline or as attachments. The following table summarizes key disclosed RTF parsing CVEs in Microsoft software:
| CVE ID | Description | Affected Software | Disclosure/Patch Date |
|---|
| CVE-2023-21716 | Heap corruption in RTF font table parsing leading to RCE | Microsoft Word 2013–2021 | March 14, 2023 |
| CVE-2016-0010 | Heap overflow in RTF document handling | Microsoft Office 2007–2016 | January 12, 2016 |
| CVE-2012-0158 | Stack buffer overflow in RTF parser (MS12-029) | Microsoft Office 2003–2010 | April 10, 2012 |
| CVE-2010-3333 | Use-after-free in RTF field code parsing | Microsoft Office 2003–2010 | November 9, 2010 |
These entries are drawn from official advisories and NVD details, highlighting recurring patterns in memory-unsafe parsing logic.[41][42]
Exploits leveraging these vulnerabilities have been observed in targeted attacks and phishing campaigns, where adversaries craft RTF files to bypass antivirus detection due to the format's relative under-scrutiny compared to XML-based alternatives like DOCX; for example, CVE-2023-21716 samples were distributed via email lures, chaining parser flaws with embedded OLE payloads to drop malware post-exploitation. In 2017, variants exploiting related RTF flaws (e.g., tied to CVE-2017-11826 delivery) used politically themed decoys to induce opens, demonstrating RTF's utility for social engineering vectors. Third-party parsers, such as in Atlantis Word Processor (CVE-2018-4040), exhibit analogous uninitialized pointer issues, underscoring that vulnerabilities are not confined to Microsoft but arise from incomplete adherence to secure parsing practices across ecosystems. Patches mitigate known issues, yet unupdated systems and zero-day variants persist as risks, particularly in environments with legacy RTF support.[43][44][45]
Role in Phishing and Malware Delivery
Rich Text Format (RTF) files have been exploited in phishing campaigns as attachments that masquerade as legitimate documents, leveraging parsing vulnerabilities in applications like Microsoft Word to deliver malware without requiring user-enabled macros. Attackers embed Object Linking and Embedding (OLE) objects or malformed structures within RTF files, which, upon opening, trigger remote code execution (RCE) flaws in the RTF parser, allowing payload download and installation. For instance, in a 2018 campaign observed by cybersecurity analysts, RTF attachments distributed information-stealing trojans and spyware, evading initial scans due to RTF's text-based appearance concealing binary exploits.[46] [45]
A prominent technique, RTF template injection, emerged around December 2021, enabling phishing attachments to reference external malicious templates hosted remotely, which fetch and execute payloads upon rendering. This method, adopted by advanced persistent threat (APT) actors including nation-state groups, bypasses email filters by avoiding direct embedding of executables and has proliferated due to its simplicity and evasion of macro-detection tools. Security firms reported its use in targeted attacks, where the RTF file's decoy content lures victims to open it in vulnerable viewers, triggering HTTP requests to attacker-controlled servers for template retrieval and subsequent malware deployment.[47] [48] [49]
Specific vulnerabilities have amplified RTF's utility in malware delivery. CVE-2017-0199, disclosed in May 2017, involved an RCE in how Microsoft Office handled RTF-embedded HTA objects, exploited in spear-phishing for fileless attacks that executed code directly in memory. Similarly, CVE-2017-11826, patched in November 2017, was weaponized in politically themed RTF documents to propagate malware via equation editor flaws. More recently, CVE-2023-21716, identified in March 2023, stems from heap corruption in Word's RTF font table parser, enabling attackers to send malicious RTF emails or files that achieve RCE when processed, often in phishing vectors targeting unpatched systems. These exploits persist because RTF's backward compatibility encourages parsing in diverse environments, including email previews, heightening delivery success rates.[50] [43] [38]
RTF's role extends to obfuscation, where attackers insert junk data or polymorphic structures to defeat signature-based antivirus, as noted in reverse-engineering analyses of phishing samples. By October 2024, RTF attachments had risen in phishing kits, often paired with personalized lures and URL tricks to exploit trust in document formats, underscoring RTF's evolution as a preferred vector over more heavily filtered types like .docm. Mitigation relies on updated software, behavioral detection of anomalous network fetches from documents, and content disarmament to strip executable elements prior to parsing.[51] [52]
Criticisms and Limitations
Syntax Complexity and File Bloat
The Rich Text Format (RTF) employs a markup-based syntax comprising plain text content interleaved with control words—sequences beginning with a backslash followed by a keyword (e.g., \b for boldface), optional numeric parameters, and termination by a space or newline—alongside control symbols like apostrophes for hexadecimal data and nested groups delimited by curly braces to encapsulate scopes such as paragraphs or tables.[15][53] This structure enables detailed, device-independent formatting specifications but demands intricate parsing logic to resolve interdependencies, such as referencing indices from header tables for fonts (\fonttbl) or colors (\colortbl), often spanning hundreds of potential control codes per document.[15]
Such syntactic verbosity contributes to file bloat, as markup overhead frequently rivals or exceeds the underlying text volume; for instance, RTF's requirement for explicit, repetitive declarations of styles and resources results in files where formatting codes inflate sizes by factors of 10 or more relative to plain text equivalents.[54] Converting a 2.3 MB binary Word document to RTF can yield a 43.9 MB file, attributable to the expansion of compressed elements into uncompressed, self-contained markup without optimization.[55] Embedding images exacerbates this, as RTF typically converts them to bulky uncompressed formats like TIFF; a text-only RTF of 1 MB augmented with 5 MB of JPEGs may balloon to 103 MB due to hex-encoded pixel data and associated headers.[56][26]
The absence of native compression mechanisms, combined with implementation-specific expansions during saves or edits—such as regenerating full style tables—leads to disproportionate growth even from trivial modifications, rendering RTF inefficient for large-scale or image-heavy documents compared to zipped XML-based alternatives.[57][58] This bloat stems causally from RTF's design priorities of interchangeability and readability over compactness, prioritizing explicitness in a pre-compression era but hindering modern storage and transmission.[54]
Proprietary Aspects Versus Open Standards
The Rich Text Format (RTF) originated as a proprietary document interchange format developed by Microsoft Corporation, with its initial specification released in 1987 to enable cross-platform compatibility between word processing applications such as Microsoft Word and early Macintosh tools.[1] Although Microsoft has published detailed specifications—culminating in version 1.9.1 in March 2008—the format's evolution remains solely under the company's discretion, without oversight from an independent standards organization like ISO or OASIS.[14] This proprietary control manifests in Microsoft-specific extensions, such as those for Outlook's RTF handling documented in protocols like MS-OXRTFEX, which encapsulate additional content types not universally supported across implementations.[12] Consequently, third-party developers face challenges in achieving full fidelity, as undocumented or proprietary mappings can lead to rendering inconsistencies, particularly for advanced features like embedded objects or compression algorithms tied to Microsoft products.
Open standards, by comparison, prioritize collaborative governance and vendor neutrality, features absent in RTF. For instance, the Open Document Format (ODF), developed by OASIS and standardized as ISO/IEC 26300 since 2006, allows input from multiple organizations, fostering broader interoperability and reducing dependence on any single vendor's roadmap.[59] Similarly, HTML, maintained by the W3C since 1991, benefits from open, consensus-driven updates that enable seamless evolution across ecosystems without proprietary extensions disrupting compatibility.[60] These standards mitigate risks inherent to proprietary formats, such as potential discontinuation—RTF development has stalled post-2008, leaving gaps in support for modern requirements like Unicode subsets beyond basic 7-bit ASCII handling in early versions—or legal ambiguities around implementation licensing, as no explicit open-source-friendly license governs RTF's use despite its public spec. Open standards thus promote long-term preservation through community-driven maintenance, whereas RTF's proprietary status ties its viability to Microsoft's ongoing interest, historically limiting widespread adoption in favor of formats like DOCX.[2]
A key limitation of RTF's proprietary model is the potential for ecosystem lock-in, where Microsoft-optimized features, such as RTF compression in [MS-OXRTFCP], prioritize internal protocols over universal accessibility, complicating reverse-engineering efforts for non-Microsoft parsers.[14] In open standards, transparent processes and mandatory conformance testing ensure predictable behavior, enhancing trust for archival and cross-vendor scenarios; RTF, while enabling basic interchange, lacks such assurances, contributing to its niche role despite early cross-platform ambitions.[61] This contrast underscores how proprietary formats like RTF, even with published specs, yield to open alternatives in scalability and innovation, as evidenced by declining RTF usage in favor of ODF or HTML for document longevity.[59]
Comparisons to Alternatives like HTML and ODF
RTF employs a linear, plain-text syntax with control words (e.g., \b for bold) to encode document formatting, making it suitable for simple rich text interchange but less efficient than HTML's tag-based structure for rendering styled content. HTML, governed by W3C standards since 1991, separates content from presentation via tags and CSS, enabling compact encoding of complex layouts, hyperlinks, and embedded media that RTF supports only in rudimentary forms, such as bitmap images without native hyperlinks. This results in RTF files often exceeding HTML equivalents in size for equivalent formatting due to repetitive control sequences, as RTF lacks CSS-like inheritance mechanisms.[60][20][62]
Parsing RTF demands handling its nested group structures (delimited by braces), which introduces complexity and potential fidelity loss across applications, unlike HTML's more modular parsing supported by ubiquitous browsers and libraries. While RTF preserves fixed-layout formatting better in legacy word processors, HTML's extensibility through JavaScript and standards evolution allows dynamic content unavailable in RTF, though HTML documents may require conversion tools for print fidelity, highlighting RTF's niche as a static document format rather than a versatile markup system. RTF's limitations in advanced features, such as absent support for forms or vector graphics, further underscore its inferiority for modern web-oriented or interactive text handling compared to HTML.[60][28][20]
In contrast to ODF, an open XML-based standard ratified by ISO/IEC 26300 in 2006 and maintained by OASIS, RTF's proprietary origins—stemming from Microsoft's 1987 specification—limit its extensibility and conformance to neutral governance. ODF packages content in zipped XML files supporting comprehensive office features like metadata, stylesheets, digital signatures, and embedded macros, which RTF omits or handles inadequately, restricting RTF to basic text, paragraphs, and simple tables without robust accessibility or scripting.[63][59][64]
ODF's modular structure facilitates smaller, more maintainable files for complex documents versus RTF's verbose syntax, which balloons file sizes—e.g., a formatted report in RTF can be 2-5 times larger than ODF due to unoptimized control word repetition—while enabling better cross-application fidelity through standardized schemas. Although RTF enjoys broader legacy support in proprietary software, ODF's open nature reduces vendor lock-in risks, as evidenced by its adoption in open-source suites like LibreOffice since 2005, whereas RTF's stagnant development post-version 1.9 (circa 2008) hampers adaptation to evolving needs like enhanced security or internationalization.[63][28][59]
Implementations and Ecosystem
Native Software Support
Microsoft WordPad, bundled with Microsoft Windows from version 95 (released August 24, 1995) through Windows 10, provides native support for creating, editing, and saving RTF files, handling features like font changes, bold and italic text, alignment, and embedded images.[65] In Windows 11 (released October 5, 2021), WordPad is deprecated and excluded from the default installation, though it remains available for manual installation via sideloading; Microsoft advises using Microsoft Word for RTF handling in such cases.[65] [66]
Microsoft Word, introduced in 1983 and part of the Microsoft 365 suite, natively imports, edits, and exports RTF documents, supporting advanced elements including tables, headers, footers, and hyperlinks while maintaining compatibility with RTF specifications up to version 1.9.1.[67] Apple's TextEdit, the default text editor on macOS since Mac OS X 10.0 (released March 24, 2001), uses RTF as its native format for rich text documents, enabling seamless opening, editing, and saving of files with formatting like colors, lists, and basic layouts.[68]
LibreOffice Writer, a free cross-platform word processor from The Document Foundation (first released November 17, 2010), offers native RTF support for import and export, preserving most standard formatting from Microsoft-originated files, though it may alter or omit proprietary Apple RTF extensions such as certain directory-based structures.[69] [70] AbiWord, an open-source editor available on Linux distributions since 1998, provides built-in RTF editing capabilities, functioning as a lightweight alternative for WYSIWYG rich text manipulation akin to WordPad.[71]
| Operating System | Native Applications | Key RTF Features Supported |
|---|
| Windows | WordPad (pre-Windows 11), Microsoft Word | Fonts, images, tables, basic layouts[65] [67] |
| macOS | TextEdit | Colors, lists, alignment[68] |
| Linux/Cross-platform | LibreOffice Writer, AbiWord | Standard formatting, hyperlinks (with extension limitations)[69] [71] |
Third-Party Libraries and Parsers
Third-party libraries for parsing and manipulating Rich Text Format (RTF) documents have been developed across multiple programming languages, primarily as open-source projects to facilitate reading, writing, or converting RTF without proprietary Microsoft dependencies. These implementations vary in scope, with some focusing on full parsing to build document object models (DOMs), others on extraction of plain text or HTML conversion, and a few supporting RTF generation. The complexity of the RTF specification, which includes nested control words, character sets, and optional extensions, often results in partial implementations or language-specific optimizations for performance and security.[33][72]
In .NET environments, notable parsers include RtfPipe, which processes RTF streams and converts them to HTML while handling encoding and Unicode, originally adapted from earlier community efforts.[33] RTFParserKit provides modular components for event-driven parsing, enabling plain text or HTML extraction and supporting custom listeners for content events.[72] Similarly, RTF DOM Parser (also known as RtfDomParser) generates an RTF DOM tree from input documents in C#, allowing programmatic manipulation and output generation.[34] NRtfTree offers classes for comprehensive RTF management, including reading and writing, under the LGPL license.[73]
For Python, the rtfparse library constructs an in-memory tree structure from RTF files, supporting analysis of document hierarchy and content extraction.[32] striprtf simplifies RTF to plain text conversion, targeting use cases like processing medical documents.[74] In Java, OpenRTF enables both creation and editing of RTF files under LGPL and MPL licenses, providing a foundation for interoperability.[75]
JavaScript developers utilize the rtf-parser NPM package, which produces a document object from text streams for general RTF handling.[76] Rust's rtf-parser crate emphasizes speed and memory efficiency with no external dependencies, implementing the latest RTF specification version for safe lexing and parsing.[77] Other languages feature specialized tools, such as r2rtf in R for generating production-ready RTF tables and figures, and Ruby-RTF for basic parsing.[78][79] These libraries often prioritize subset compliance over full specification support, reflecting RTF's evolution and the practical needs of extraction over complete fidelity.[80]