Rich Text Format

From Wikipedia, the free encyclopedia

Rich Text Format
File extension: .rtf
MIME type: text/rtf
Type code: 'RTF '
Uniform Type Identifier: public.rtf
Magic: {\rtf
Developed by: Microsoft
Type of format: document file format

The Rich Text Format (often abbreviated to RTF) is a proprietary document file format developed by Microsoft in 1987 for cross-platform document interchange. Most word processors are able to read and write RTF documents. Unlike most word processing formats, RTF is human-readable.

It should not be confused with enriched text which is a completely different specification.

Contents

[edit] Sample RTF document

As an example, the following RTF code:

{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\par
This is some {\b bold} text.\par
}

would be rendered like this when read by an appropriate word processor:


This is some bold text.

A backslash (\) starts an RTF control code. The \par control code indicates a new line, and \b switches to a bold typeface. Brackets ({ and }) define a group; the example uses a group to limit the scope of the \b control code. Everything else will be treated as clear text, or the text to be formatted. A valid RTF document is a group starting with the \rtf control code.

[edit] Character encoding

RTF is a 7-bit format. That would limit it to ASCII, but RTF can encode characters beyond ASCII by escape sequences. The character escapes are of two types: code page escapes and Unicode escapes. In a code page escape, two hexadecimal digits following an apostrophe are used for denoting a character taken from a Windows code page. For example, if control codes specifying Windows-1256 are present, the sequence \'c8 will encode the Arabic letter beh (ب).

If a Unicode escape is required, the control word \u is used, followed by a 16-bit signed decimal integer giving the Unicode codepoint number. For the benefit of programs without Unicode support, this must be followed by the nearest representation of this character in the specified code page. For example, \u1576? would give the Arabic letter beh, specifying that older programs which do not have Unicode support should render it as a question mark instead.

The control word \uc0 can be used to indicate that subsequent Unicode escape sequences within the current group do not specify a substitution character.

[edit] Common implementations

Most word processing software implementations support RTF format import and export, often making it a "common" format between otherwise incompatible word processing software.

The WordPad editor in Microsoft Windows creates RTF files by default. It once defaulted to the Microsoft Word 6.0 file format, but write support for Word documents was dropped in a security update.

The free software/open-source word processors AbiWord and OpenOffice.org can view and edit RTF files.

The default editor for Mac OS X, TextEdit, can also view and edit RTF files.

Since RTF files are text files, it’s easy to produce RTF with many programming languages, like Perl, Java, C++, Pascal, COBOL, or Lisp. Perl, for example, has the RTF::Writer module for this

[edit] See also

[edit] External links