RTF

From AbiWiki

Jump to: navigation, search

RTF (Rich Text Format) is an word processor interchange format developed by Microsoft to facilitate the exchange of documents between different tools and different operating systems.

Contents

Description

Files in this format will usually have an .rtf extension. The first RTF reader and writer shipped in 1987 as part of Microsoft Word 3.0 for Macintosh. It is the native save format for WordPad files. Some eBook readers can read files this format but it is fairly verbose so the file sizes will be larger.

RTF is an example of a markup language and uses pure text even for graphics by encoding the binary. It is capable of representing fairly complicated layouts. It can be viewed as a markup using any text editor. Returns stored in the file are ignored.

When an eBook reader claims to read RTF it does not mean that it supports all of the fonts, or all of the available constructions. There have been many versions of RTF over the years. Generally if a construction is not understood it will be ignored and not preserved in the file if it is saved.

RTF has two sections in the file, a header and a body. The header contains default information for the file such as the default font size and may contain metadata. If the file is loaded into an editor and then saved some or all of the metadata may be lost. WordPad for example saves files natively in RTF format but does not support metadata.

Tools

Just about every word processor on the planet can support RTF files. However there are differences in the way the files are produced.

  • WordPad uses RTF as its native format. It does not support images or metadata. It has a very compact footprint for files.
  • MS Word uses RTF as an exchange format. It support all features but produces a larger file than some others due to the fact that it includes information about every change to the file. Every time you save an RTF in MS word the file size will increase.

It is possible to convert RTF to HTML with RTF to HTML

Syntax

RTF files include data and control structures. The control structures include:

  • Control Words - begin with a \ and consist of case sensitve letters followed by a delimiter. A delimiter can be a space (the space itself will be ignored), a number or - indicating a parameter for the control word, or another character which will start a new sequence.
  • Control Symbols - begin with a \ and consist of one special character. An example is \~ which is the symbol for a non-breaking space.
  • Groups - are delimited with { and } and are used to specify the text and the attributes of that text.
  • Destinations are special control words that specify that the text goes somewhere else in the document. An example is \footnote. The footnote itself will be defined as a group.

examples

  • Here is an example of an RTF document using legal syntax.
{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard
This is some {\b bold} text.\par
}

This would be displayed as:

This is some bold text.

Bolding could also been achieved using \b bold\b0

  • Here is the same document saved in wordpad
{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033
{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}
\viewkind4\uc1\pard\f0\fs24 This is some \b bold\b0  text.\par}
  • Here is a similar document saved in MS Word 2002:
{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033
\deflangfe1033
{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\f36\froman\fcharset238\fprq2 Times New Roman CE;}
{\f37\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f39\froman\fcharset161
\fprq2 Times New Roman Greek;}{\f40\froman\fcharset162\fprq2 Times New Roman Tur;}
{\f41\froman\fcharset177\fprq2 Times New Roman (Hebrew);}
{\f42\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f43\froman\fcharset186
\fprq2 Times New Roman Baltic;}{\f44\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}}
{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255; 
\red0\green255\blue0;\red255
\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;
\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;
\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;
\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\widctlpar 
\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 
\fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive 
\ssemihidden Default Paragraph Font;}
{\*\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3
\trpaddfr3\trcbpat1\trcfpat1\tblind0\tblindtype3\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl
\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv 
\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap
\fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}}
{\*\rsidtbl \rsid604983\rsid1011638\rsid2916272\rsid3999307\rsid4476289
\rsid6029320\rsid8616248\rsid9443644\rsid9792149\rsid12854369\rsid12999621\rsid14312442
\rsid14449629\rsid15040078\rsid15151528\rsid15999791\rsid16668571}
{\*\generator Microsoft Word 10.0.6846;}{\info{\title This word is bold}{\author Author1}
{\operator Author1}{\creatim\yr2008\mo9\dy17\hr12\min45}{\revtim\yr2008\mo9\dy17\hr12\min45}
{\version2}{\edmins2}{\nofpages1}{\nofwords2}{\nofchars17}{\*\company  }
{\nofcharsws18}{\vern16393}{\*\password 00000000}}{\*\xmlnstbl }
\paperw12240\paperh15840\margl1800\margr1800\margt1440\margb1440\gutter0 \widowctrl\ftnbj
\aenddoc\grfdocevents0\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb
\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1800
\dgvorigin1440\dghshow1
\dgvshow1\jexpand\viewkind1\viewscale85\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine
\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl
\snaptogridincell\allowfieldendsel\wrppunct\asianbrkrule\rsidroot15999791 \fet0
{\*\wgrffmtfilter 013f}\sectd \linex0\endnhere\sectlinegrid360\sectdefaultcl\sftnbj 
{\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1
\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang 
{\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}
{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}
{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}
{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}
{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}
{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}
\pard\plain \ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0
\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 
{\insrsid16668571 This }{\b\insrsid16668571\charrsid16668571 word}{\insrsid16668571  is bold.}
{\insrsid4476289 \par }}

It says: This word is bold. Note that some metadata is included. It includes revision data and will get longer every time it is saved.

  • Here is similar text saved in AbiWord. It is a little cleaner and also supports metadata
{\rtf1\ansi\ansicpg1252\deff0
{\fonttbl
{\f0\froman\fcharset0\fprq2\fttruetype Times New Roman;}
{\f1\fswiss\fcharset0\fprq2\fttruetype Arial;}
{\f2\fnil\fcharset0\fprq2\fttruetype Dingbats;}
{\f3\froman\fcharset0\fprq2\fttruetype Symbol;}
{\f4\fmodern\fcharset0\fprq1\fttruetype Courier New;}}
{\colortbl
\red0\green0\blue0;
\red255\green255\blue255;}
{\stylesheet
{\s1\fi-431\li720\sbasedon28\snext28Contents 1;}
{\s2\fi-431\li1440\sbasedon28\snext28Contents 2;}
{\s3\fi-431\li2160\sbasedon28\snext28Contents 3;}
{\s8\fi-431\li720\sbasedon28Lower Roman List;}
{\s5\tx431\sbasedon24\snext28Numbered Heading 1;}
{\s6\tx431\sbasedon25\snext28Numbered Heading 2;}
{\s7\fi-431\li720Square List;}
{\*\cs11\sbasedon28Endnote Text;}
{\s4\fi-431\li2880\sbasedon28\snext28Contents 4;}
{\s9\fi-431\li720Diamond List;}
{\s10\fi-431\li720Numbered List;}
{\*\cs12\fs20\superEndnote Reference;}
{\s13\fi-431\li720Triangle List;}
{\s14\tx431\sbasedon26\snext28Numbered Heading 3;}
{\s15\fi-431\li720Dashed List;}
{\s16\fi-431\li720\sbasedon10Upper Roman List;}
{\s17\sb440\sa60\f1\fs24\b\sbasedon28\snext28Heading 4;}
{\s18\fi-431\li720Heart List;}
{\s34\fi-431\li720Box List;}
{\s20\fi-431\li720\sbasedon10Upper Case List;}
{\s21\fi-431\li720Bullet List;}
{\s22\fi-431\li720Hand List;}
{\*\cs23\fs20\sbasedon28Footnote Text;}
{\s24\sb440\sa60\f1\fs34\b\sbasedon28\snext28Heading 1;}
{\s25\sb440\sa60\f1\fs28\b\sbasedon28\snext28Heading 2;}
{\s19\qc\sb240\sa120\f1\fs32\b\sbasedon28\snext28Contents Header;}
{\s27\fi-431\li720Tick List;}
{\s26\sb440\sa60\f1\fs24\b\sbasedon28\snext28Heading 3;}
{\s29\fi-431\li720\sbasedon10Lower Case List;}
{\s30\li1440\ri1440\sa120\sbasedon28Block Text;}
{\s36\f4\sbasedon28Plain Text;}
{\s32\tx1584\sbasedon5\snext28Section Heading;}
{\s33\fi-431\li720Implies List;}
{\s28\f0\fs24Normal;}
{\s35\fi-431\li720Star List;}
{\*\cs31\fs20\superFootnote Reference;}
{\s37\tx1584\sbasedon5\snext28Chapter Heading;}}
\kerning0\cf0\ftnbj\fet2\ftnstart1\ftnnar\aftnnar\ftnstart1\aftnstart1\aenddoc\revprop3
{\info\uc1{\title Title1}{\author Author1}{\company publisher1}{\subject Subject1}
{\doccomm This is a description}{\category cat1}}\deftab720\viewkind1\paperw12240
\paperh15840\margl1440\margr1440\widowctrl
\sectd\sbknone\colsx0\marglsxn1800\margrsxn1800\pgncont\ltrsect
\pard\plain\ltrpar\ql\sl240\slmult1\itap0{\f0\fs24\lang1033{\*\listtag0}
\abinodiroverride\ltrch This }{\f0\fs24\b\lang1033{\*\listtag0}word}{\f0\fs24\lang1033
{\* \listtag0} is bold.}{\f0\fs24\lang1033{\*\listtag0}\par}}

It says: This word is bold.

Note that all files begin with \rtf1 and this is followed with the character encoding. Unicode is supported as well as ANSI. Many readers will terminate reading the file if another \rtf1 is encounter however Abiword will concatenate the sections together into one document.

For more information

The specifications can be found on the Microsoft web site.

Personal tools