RTF Bullet List Example
Asked Answered
rtf
C

6

14

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

  • Hello
  • World
    • Nested (but with square as bullet please)
    • Also nested (also square bullet)
  • and regular again

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

Chercherbourg answered 12/3, 2013 at 17:25 Comment(0)
M
12

If you looked in the Word or Wordpad formatted RTF long enough, you would find some lines that look like this:

{\f2 {\pntext \'B7\tab}{*\pn\pnlvlblt\pnstart1{\pntxtb\'B7}}{\ltrch This is a test.}\li720\ri0\sa0\sb0\jclisttab\tx720\fi-360\ql\par}

{\f2 {\pntext \'B7\tab}{*\pn\pnlvlblt\pnstart1{\pntxtb\'B7}}{\ltrch So is this.}\li720\ri0\sa0\sb0\jclisttab\tx720\fi-360\ql\par}

This will format like this

  • This is a test.
  • So is this.

Nested lists are probably a little bit harder, but this is what you'll want if you don't have any nested lists.

Now it depends on what you want to do with this. If you're just displaying it, every tag means something useful. When I worked with lists, I was converting them to HTML, so a lot of the formatting tags (\li,\ri,\tx, etc.), I didn't need for my application because I was just using <ol>,<ul> and <li> tags. The main thing to see it the tag \pnlvlblt, which makes this list a bulleted list. Also, \'B7 is the actual unicode tag for the bullet, ·

The most updated specification of RTF is here:

https://www.microsoft.com/en-us/download/details.aspx?id=10725

Marcie answered 28/6, 2013 at 20:42 Comment(3)
I've looked high and low for propah RTF bullet markup, and this absolutely NAILED IT. Thank you very much! :-)Vinificator
Isn't \u8226? the bullet point unicode tag? I think \'B7 is the "middle dot".Breadfruit
This does not format correctly for me in RTF editbox on Windows.formsCellulous
O
6

A simple, straightforward way is to just use characters as follows:

\line \bullet Hello
\line \bullet World
\line \tab \bullet Nested (but with square as bullet please)
\line \tab \u9632 Also nested (also square bullet)
\line \tab and regular again

You could still parse the RTF back to a tag-based format afterwards, with enclosing tags as hierarchy information is being provided by the indentation.

As you can see, any sort of unicode usage is fine. For the unicodes see this site.

For more information, be sure to consult the Bullets and Numbering section of the RTF Specifications.

Onionskin answered 31/10, 2013 at 6:28 Comment(4)
+1 from me! Just a note though for people out there. If for presentation only, this is very fine. However, I used a component to convert RTF to HTML and then from HTML to XML. For this use case, the solution above is not as neat, because bullets like those above won't be automatically converted to HTML <ul> tags.Cellulous
@Prof.Falken did you ever find a way to convert the rtf \bullet character to html? I am thinking of replacing it with an acceptable unicode character before I convert.Shenashenan
I don't remember honestly. I made some kind of un-holy modified XHTML-parser I think. In any case, I made the conversion in 3 steps, that's about as much as I can remember right now without looking at the code. @ShenashenanCellulous
Thanks @Prof.Falken. I'll try doing a character-level substitution first. If that fails, "XHTML-parser".Shenashenan
M
3

Here is another simple way to do it, as far as just displaying correctly on the page. All you have to do is set a block indent with \li and a negative first line indent with \fi, and use \bullet\tab at the start of the line.

{\rtf1\ansi\deff0
{\pard\fi-300\li300\bullet\tab Having demonstrated his model time machine to a handful of reliable witnesses, The Time Traveller, within the week, 
\par}

{\pard\fi-300\li600\bullet\tab Having demonstrated his model time machine to a handful of reliable witnesses, The Time Traveller, within the week, 
\par}
}

enter image description here

Marmoset answered 20/4, 2020 at 2:38 Comment(1)
Thanks, this worked with RichEditBox from UWPKatrinakatrine
B
2

I tried Saur's anser but the "Also nested (also square bullet)" line had the A of Also covered up by the square bullet. Not sure why that happened.
■lso nested (also square bullet)

I like using the line indent commands so if a line wrap happens, the wrapped text is indented as well. When you do \line \tab, anything that runs off the end of the printed page will start at the left margin instead of where your indented text started from. This is system generated by a System.Windows.Forms.RichTextBox which I pasted into (from MS-Word) and then called RichTextBox.RTF to get the code.

{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fprq2\fcharset2 Symbol;}{\f1\froman\fprq2\fcharset0 Times New Roman;}{\f2\fnil\fprq2\fcharset2 Wingdings;}{\f3\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\ltrpar\fi-360\li360\f0\fs20\'b7\tab\f1 Hello\par
\f0\'b7\tab\f1 World\par
\pard\ltrpar\fi-360\li990\f2\'a7\tab\f1 Nested (but with square as bullet please)\par
\f2\'a7\tab\f1 Also nested (also square bullet)\par
\pard\ltrpar\fi-360\li360\sa200\sl276\slmult1\f0\'b7\tab\f1 and regular again\lang1024\par
\pard\ltrpar\lang1033\f3\fs17\par
}
Brei answered 6/1, 2014 at 22:18 Comment(0)
O
2

This is for people who want to add text and bullet list to an extended wpf toolkit (wpfToolKit) richTextBox. I created this, because I had some problems with the solutions here. They didnt work for me or the \tab was too large infront of the bullet. With this implementation, you can adjust the indention infront of the bullets.

Notes for this implementation:

  • you have to play around with the indent (\li). The values have to differ by hundreds in my case to see an effect. in this example: 100 and 500.

  • using \par\pard for each line in the richtext box is important. Without it, it would indent other lines without bullets, too.

  • the header includes stuff like coloring, which you probably dont need.

Methods

public  string AddBullet(string textRow, int indent)
{
    return $@"\li{indent}{{\pntext\f1\'B7}}{{\*\pn\pnlvlblt{{\pntxtb\'B7}}}}{textRow}";
}

public  string AddNewLine(string text)
{
    return $@"{text}\par\pard ";
}


public  string AddHeader(string text, string fontName, int fontSize)
{
    return $@"{{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1031{{\fonttbl{{\f0\fnil\fcharset0 {fontName};}}{{\f1\fnil\fcharset2 Symbol;}}}}{{\colortbl ;\red0\green77\blue187;\red128\green0\blue0;\red0\green0\blue0;\red155\green0\blue211;\red81\green163\blue69;\red51\green51\blue51;}}\viewkind4\uc1\pard\sl0\slmult1\f0\fs{fontSize * 2}\lang7 {text}}}";
}

How to use the Methods

var regularRow1     = AddNewLine("AAAA");
var bulletRow1      = AddNewLine(AddBullet("BBBB", 100));
var bulletRowNested = AddNewLine(AddBullet("CCCC", 500));
var bulletRow2      = AddNewLine(AddBullet("BBBB", 100));
var regularRow2     = AddNewLine("AAAA");

var richTextWithoutHeader = regularRow1 + bulletRow1 + bulletRowNested + bulletRow2 + regularRow2;
var richText = AddHeader(richTextWithoutHeader, "Arial", 12);

Result

Result

Onward answered 11/8, 2019 at 8:21 Comment(0)
B
1

This is how I'm creating a bullet list:

{\rtf1\ansi\deff0
{{\li0\pntext\pn\pnlvlblt\pntxtb\u8226?\tab}{This is item one}\par}
{{\li0\pntext\pn\pnlvlblt\pntxtb\u8226?\tab}{This is item two}\par}
{{\li400\pntext\pn\pnlvlblt\pntxtb\u9642?\tab}{This is item three}\par}
{{\li400\pntext\pn\pnlvlblt\pntxtb\u9642?\tab}{This is item four}\par}
{{\li0\pntext\pn\pnlvlblt\pntxtb\u8226?\tab}{This is item five}\par}
}

Renders as:

enter image description here

Be aware that the multilevel list is not really threated like one in word. It's basicly a normal list with indented nodes.

Explanation:

\li0 : intend 0 (usefull for multilevel lists)

\pntext : prefix for all numbered/bulleted paragraphs

\pn : turns on paragraph numbering (also needed for bullet lists)

\pnlvlblt : this paragraph is a bullet paragraph

\pntxtb : text before (the icon)

\u8226? : unicode character for bullet point

\u9642? unicode character for small black square

\tab : adds a tab after the icon

\par : end of paragraph

Breadfruit answered 10/4, 2018 at 14:45 Comment(2)
this did not work with a wpf extended toolkit richtextbox and did not work with wordpad. Okay, it worked in word. But that does not help when working with wpfOnward
The problem with this is that continuation lines are not indented under the first line.Marmoset

© 2022 - 2024 — McMap. All rights reserved.