Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RTF Bullet List Example

Tags:

rtf

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?

like image 326
ckck Avatar asked Mar 12 '13 17:03

ckck


People also ask

Which is an example of bullet list?

A bullet list is used when creating a list of two or more items, and their order is not important. For example, a list of items you want to buy from a store could be shown in a bullet list. A number list should be used if you're creating a list of steps or directions where the order is important.

How do I add bullet points to rich text?

Adding bullet points Choose the text box you wish to have in a bullet-point list. You can either have points pre-written or add items line by line; hitting the return key to add another bullet point item on the list. Then click the bullet point tool in the properties bar.

What is bullet point format?

A bullet point is a symbol that is used in writing to introduce an item in a list. A commonly used symbol to represent a bullet point is a centered dot (•), but many different symbols and characters can be used in bullet point lists. Sometimes, bulleted lists even use numbers and/or letters.


6 Answers

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

like image 124
Mike Blyth Avatar answered Sep 26 '22 04:09

Mike Blyth


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

like image 35
ToastyMallows Avatar answered Sep 25 '22 04:09

ToastyMallows


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.

like image 25
Lorenz Lo Sauer Avatar answered Sep 25 '22 04:09

Lorenz Lo Sauer


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
}
like image 27
user922020 Avatar answered Sep 24 '22 04:09

user922020


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

like image 37
Blechdose Avatar answered Sep 23 '22 04:09

Blechdose


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

like image 32
NtFreX Avatar answered Sep 26 '22 04:09

NtFreX