Search code examples
documentrtfdocumentation-generation

RTF Numbered List Example


It seems impossible to find a very simple working example for an RTF numbered list that looks like this:

1. The first line
2. The second line

I tried to make a small sample by using Word but they produce a lot of garbage. Can anyone help out?

Somewhere I got this, but it's not working, only the first line is bulleted, more lines get appended to the first line.

\pard{\pntext\f0 1.\tab}\*\pn\pnlvlbody\pnf0\pnindent0\pnstart1\pndec{\pntxta.}}\fi-360\li480\sa50\sl0\slmult1 The first line

(My target is the RTF Edit box of Windows, so I'm not all concerned about backwards compatibility with older RTF readers like Word 6 which do not understand numbered lists and need fallback text formatted to look list numbers.)


Solution

  • The following works for me with the Windows RichTextBox control and Word version 1803:

    {\rtf1
    \pard{\pntext\f0 1.\tab}\*\pn\pnlvlbody\pnf0\pnindent0\pnstart1\pndec{\pntxta.}
    \fi-360\li480\sa50\sl0\slmult1 The first line\par The second line\par The third line\par
    \pard\par normal text
    }
    

    Inconsistencies come when you try to end the list without a blank line between the last list item and the normal text - Word displays it correctly, but the RTB control still shows "normal text" as part of the list (i.e. number 4.) if you remove the \par after \pard.

    numbered list in RTB control