The Paragraph class allows you to separate the content into paragraphs. It is responsible for displaying inline elements such as Run, FloatingImage, ImageInline etc. It is also possible to configure the appearance of the paragraph by modifying its parameters.
The code snippet from Example 1 creates and inserts a Paragraph in a Section.
C# Example 1: Insert paragraph in section
Paragraph paragraph = new Paragraph(document); section.Blocks.Add(paragraph);
The parent BlockContainer element (in this case - the section) should 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. In Example 2 is demonstrated how to add a paragraph at the beginning of a section.
C# Example 2: Insert a paragraph at a specific position of the Blocks collection
Paragraph paragraph = new Paragraph(document); section.Blocks.Insert(0, paragraph);
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.
C# Example 3: Create a new paragraph and add it to a section
Paragraph paragraph = section.Blocks.AddParagraph();
Inserting a new Paragraph in the document can also be achieved with the RadFlowDocumentEditor class.
C# Example 4: Insert a paragraph using the RadFlowDocumentEditor
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(GetDocument()); Paragraph paragraph = editor.InsertParagraph();
Paragraph exposes several properties that allow you to customize the layout of the elements placed underneath it. Here is a list of them:
Properties: Gets all paragraph properties as ParagraphProperties object. More info on how to use section properties can be found in 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 elements.
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 if the Paragraph should be rendered on one page when the document is shown in page view mode.
KeepWithNextParagraph: Indicates if the Paragraph should be 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 TOC field. The default value is Level9 – no level.
ApplyEastAsianLineBreakingRules: Specifies whether East-Asian line breaking rules are applied to the Paragraph.
PageBreakBefore: Specifies if the Paragraph should be 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 are ignored when preceding/following paragraph has same paragraph style.
MirrorIndents: Defines whether left and right indents should be swapped on odd pages.
Indentation: Defines a set of indentations which can be applied to a Paragraph element through a ParagraphIndentation object. ParagraphIndentation is a composite one 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 which is applied to the first line of the paragraph.
HangingIndent: Specifies a value which 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 which is applied to the left side of the whole paragraph.
- RightIndent: Indicates the indentation which 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 which is used to lay the pattern color over the background color for the shading.
- BackgroundColor: Specifies 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 is referencing list style. The default value is -1, which means that list style is not referenced.
TabStops: Immutable collection, which holds the TabStops of the Paragraph. More information can be found in the TabStop article
You can add inline elements to a Paragraph instance.
In Example 5 is illustrated how to add a run to an existing paragraph.
C# Example 5: Insert run in a paragraph
Run run = paragraph.Inlines.AddRun();
For more information about Run element, you can read this article.
Example 6 adds an inline image to an existing paragraph.
C# Example 6: Insert image inline
ImageInline imageInline = paragraph.Inlines.AddImageInline();
For more information about ImageInline element, you can read this article.
The code snippet from Example 7 adds a floating image to an existing paragraph.
C# Example 7: Add floating image
FloatingImage floatingImage = paragraph.Inlines.AddFloatingImage();
For more information about FloatingImage element, you can read this article.
In Example 8 it is demonstrated how to add a tab stop to the paragraph's collection.
C# Example 8: Insert TabStop
TabStop tabstop = new TabStop(Unit.InchToDip(2), TabStopType.Center, TabStopLeader.Hyphen); paragraph.TabStops = paragraph.TabStops.Insert(tabstop);
You can refer to the TabStop article for more details about this element.