# Paragraph

The `Paragraph` class allows you to separate the content into paragraphs. It is responsible for displaying inline elements such as [Run](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/run), [FloatingImage](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/floatingimage), [ImageInline](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/imageinline), and others. You can also configure the appearance of the paragraph by modifying its parameters.

* [Inserting a Paragraph](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/paragraph#inserting-a-paragraph)

* [Modifying a Paragraph](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/paragraph#modifying-a-paragraph)

* [Operating with a Paragraph](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/paragraph#operating-with-a-paragraph)

## Inserting a Paragraph

Paragraphs can be added as a child of a [BlockContainer](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Flow.Model.BlockContainerBase.html) element—[Section](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/section), [TableCell](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/tablecell), [Headers and Footers](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/headers-footers)—through the `Blocks` collection.

The code snippet from **Example 1** creates and inserts a `Paragraph` in a `Section`.

**Example 1: Create a paragraph and add it to a section block collection**

```C#
RadFlowDocument document = new RadFlowDocument();
			Section section = document.Sections.AddSection();

			Paragraph paragraph = new Paragraph(document);
			section.Blocks.Add(paragraph);
```

> tip The parent `BlockContainer` element (in this case, the section) must belong to the same document that is passed to the constructor of the `Paragraph`.

You can add a paragraph at a specific index in the `Blocks` collection of a `BlockContainer` using the `Insert()` method. **Example 2** demonstrates how to add a paragraph at the beginning of a section.

**Example 2: Insert a paragraph at the beginning of a section block collection**

```C#
Paragraph paragraph1 = new Paragraph(document);
			section.Blocks.Insert(0, paragraph1);
```

You can also use the `AddParagraph()` method of the `Blocks` collection of a `BlockContainer`. The method creates a new `Paragraph` instance, adds it to the container, and returns it.

**Example 3: Create and add a paragraph with the AddParagraph method**

```C#
Paragraph paragraph2 = section.Blocks.AddParagraph();
```

You can also insert a new `Paragraph` in the document with the [RadFlowDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor) class.

**Example 4: Insert a new paragraph with RadFlowDocumentEditor**

```C#
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(new RadFlowDocument());
			Paragraph paragraph3 = editor.InsertParagraph();
```

## Modifying a Paragraph

`Paragraph` exposes several properties that allow you to customize the layout of the elements placed underneath it. The following list describes them:

* `Properties`: Gets all paragraph properties as a `ParagraphProperties` object. More information on how to use section properties is available in the [Style Properties](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/style-properties) article.

* `StyleId`: Represents the ID of the style applied on the `Paragraph` element.

* `Inlines`: Represents the inline elements in the paragraph. Exposes methods for adding a `Run`, an `ImageInline`, and a `FloatingImage` element.

* `FlowDirection`: Specifies the text flow direction. The default value is *LeftToRight*.

* `TextAlignment`: Represents the alignment of the text inside the `Paragraph`.

* `Spacing`: Defines the `Paragraph` spacing.

* `KeepOnOnePage`: Indicates whether the `Paragraph` is rendered on one page when the document is shown in page view mode.

* `KeepWithNextParagraph`: Indicates whether the `Paragraph` is rendered at least partly on the same page with the following paragraph when this is possible and when the document is shown in page view mode.

* `OutlineLevel`: Defines the level of the `Paragraph` in a TOC field. The default value is Level9 (no level).

* `ApplyEastAsianLineBreakingRules`: Specifies whether East-Asian line breaking rules are applied to the `Paragraph`.

* `PageBreakBefore`: Specifies whether the `Paragraph` is rendered on a new page when the document is shown in page view mode.

* `Borders`: Defines the borders of the `Paragraph`.

* `ContextualSpacing`: Defines whether spacing before/after is ignored when the preceding/following paragraph has the same paragraph style.

* `MirrorIndents`: Defines whether left and right indents are swapped on odd pages.

* `Indentation`: Defines a set of indentations that can be applied to a `Paragraph` element through a `ParagraphIndentation` object. `ParagraphIndentation` is a composite object and its properties are listed below. All the values of these properties are in device independent pixels (1/96 inch).

  * `FirstLineIndent`: Indicates the additional indentation that is applied to the first line of the paragraph.
  * `HangingIndent`: Specifies a value that is removed from the indentation of the first line of the paragraph, by moving the indentation on the first line back towards the beginning of the direction of text flow.
  * `LeftIndent`: Indicates the indentation that is applied to the left side of the whole paragraph.
  * `RightIndent`: Indicates the indentation that is applied to the right side of the whole paragraph.

* `Shading`: Represents the shading applied to the paragraph. It is a composite object and is read-only. You can obtain the following properties from it:
  * `BackgroundColor`: Specifies the background color for the shading.
  * `PatternColor`: Specifies the pattern color for the shading.
  * `Pattern`: Specifies the pattern that is used to lay the pattern color over the background color for the shading.

* `AllowOverflowPunctuation`: Defines whether the last punctuation character on a line can overflow in paragraph margin/indent.

* `ListId`: Specifies the list ID.

* `ListLevel`: Gets a value indicating that the paragraph references a list style. The default value is -1, meaning that list style is not referenced.

* `TabStops`: Immutable collection that holds the tab stops of the `Paragraph`. More information is available in the [TabStop](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/tabstop) article.

## Operating with a Paragraph

You can add inline elements to a `Paragraph` instance.

### Adding a Run

**Example 5** illustrates how to add a run to an existing paragraph.

**Example 5: Add a new run to an existing paragraph**

```C#
Run run = paragraph.Inlines.AddRun();
```

For more information about the `Run` element, refer to the [Run](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/run) article.

### Adding an ImageInline

**Example 6** adds an inline image to an existing paragraph.

**Example 6: Add an inline image to an existing paragraph**

```C#
ImageInline imageInline = paragraph.Inlines.AddImageInline();
```

For more information about the `ImageInline` element, refer to the [ImageInline](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/imageinline) article.

### Adding a FloatingImage

The code snippet from **Example 7** adds a floating image to an existing paragraph.

**Example 7: Add a floating image to an existing paragraph**

```C#
FloatingImage floatingImage = paragraph.Inlines.AddFloatingImage();
```

For more information about the `FloatingImage` element, refer to the [FloatingImage](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/floatingimage) article.

### Adding a TabStop

**Example 8** demonstrates how to add a tab stop to the paragraph's collection.

**Example 8: Insert a centered tab stop with a hyphen leader at 2 inches**

```C#
TabStop tabstop = new TabStop(Telerik.Documents.Media.Unit.InchToDip(2), TabStopType.Center, TabStopLeader.Hyphen);
			paragraph.TabStops = paragraph.TabStops.Insert(tabstop);
```

You can refer to the [TabStop](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/tabstop) article for more details about this element.

### Setting Borders

**Example 9** shows how to create borders and set them to a `Paragraph`.

**Example 9: Apply black and red single-line borders to a paragraph**

```C#
Border blackBorder = new Border(1, BorderStyle.Single, new ThemableColor(Colors.Black));
			Border redBorder = new Border(2, BorderStyle.Single, new ThemableColor(Colors.Red));

			paragraph.Borders = paragraph.Borders.SetLeft(blackBorder).SetRight(redBorder).SetTop(blackBorder).SetBottom(redBorder);
```

## See Also

* [Paragraph API Reference](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Flow.Model.Paragraph.html)
* [Section](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/section)
* [TableCell](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/tablecell)
* [Headers and Footers](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/headers-footers)
* [Run](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/run)
* [Bullet List with Paragraph Styles](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/create-bullet-list-using-paragraph-styles-radwordsprocessing)
