Paragraph Formatting

GemBox.Document supports paragraph formatting options like alignment, indentation, spacing, borders, tabs and many others.

Following sample shows some of the available paragraph formatting options.

Screenshot

Paragraph Formatting Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using System;
2using System.Globalization;
3using GemBox.Document;
4
5class Sample
6{
7    [STAThread]
8    static void Main(string[] args)
9    {
10        // If using Professional version, put your serial key below.
11        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
12
13        DocumentModel document = new DocumentModel();
14
15        document.Sections.Add(
16            new Section(document,
17                new Paragraph(document, "Text is centered")
18                {
19                    ParagraphFormat = new ParagraphFormat
20                    {
21                        Alignment = HorizontalAlignment.Center
22                    }
23                },
24                new Paragraph(document, "This paragraph has the following properties: Left indentation is 10 points, right indentation is 10 points, hanging indentation is 20 points, line spacing is exactly 20 points, space before and space after are 20 points.")
25                {
26                    ParagraphFormat = new ParagraphFormat
27                    {
28                        LeftIndentation = 10,
29                        RightIndentation = 10,
30                        SpecialIndentation = 20,
31                        LineSpacing = 20,
32                        LineSpacingRule = LineSpacingRule.Exactly,
33                        SpaceBefore = 20,
34                        SpaceAfter = 20
35                    }
36                },
37                new Paragraph(document, "This paragraph has the following properties: Left indentation is 25 points, right indentation is 25 points, first line indentation is 25 points and line spacing is at least 10 points.")
38                {
39                    ParagraphFormat = new ParagraphFormat
40                    {
41                        LeftIndentation = 25,
42                        RightIndentation = 25,
43                        SpecialIndentation = -25,
44                        LineSpacing = 10,
45                        LineSpacingRule = LineSpacingRule.AtLeast
46                    }
47                }));
48
49        Paragraph paragraphWithBorders = new Paragraph(document, "The following paragraph is surrounded with the borders.");
50        paragraphWithBorders.ParagraphFormat.Borders.SetBorders(MultipleBorderTypes.Outside, BorderStyle.Single, Color.Black, 2);
51        document.Sections[0].Blocks.Add(paragraphWithBorders);
52
53        document.Save("Paragraph Formatting.docx");
54    }
55}
1Imports System
2Imports System.Globalization
3Imports GemBox.Document
4
5Module Samples
6
7    Sub Main()
8
9        ' If using Professional version, put your serial key below.
10        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
11
12        Dim document As DocumentModel = New DocumentModel
13
14        document.Sections.Add(
15            New Section(document,
16                New Paragraph(document, "Text is centered") With {
17                    .ParagraphFormat = New ParagraphFormat() With {
18                        .Alignment = HorizontalAlignment.Center
19                    }
20                },
21                New Paragraph(document, "This paragraph has the following properties: Left indentation is 10 points, right indentation is 10 points, hanging indentation is 20 points, line spacing is exactly 20 points, space before and space after are 20 points.") With {
22                    .ParagraphFormat = New ParagraphFormat() With {
23                        .LeftIndentation = 10,
24                        .RightIndentation = 10,
25                        .SpecialIndentation = 20,
26                        .LineSpacing = 20,
27                        .LineSpacingRule = LineSpacingRule.Exactly,
28                        .SpaceBefore = 20,
29                        .SpaceAfter = 20
30                    }
31                },
32                New Paragraph(document, "This paragraph has the following properties: Left indentation is 25 points, right indentation is 25 points, first line indentation is 25 points and line spacing is at least 10 points.") With {
33                    .ParagraphFormat = New ParagraphFormat() With {
34                        .LeftIndentation = 25,
35                        .RightIndentation = 25,
36                        .SpecialIndentation = -25,
37                        .LineSpacing = 10,
38                        .LineSpacingRule = LineSpacingRule.AtLeast
39                }}))
40
41        Dim paragraphWithBorders As New Paragraph(document, "The following paragraph is surrounded with the borders.")
42        paragraphWithBorders.ParagraphFormat.Borders.SetBorders(MultipleBorderTypes.Outside, BorderStyle.Single, Color.Black, 2)
43        document.Sections(0).Blocks.Add(paragraphWithBorders)
44
45        document.Save("Paragraph Formatting.docx")
46
47    End Sub
48
49End Module

Check next sample or find out more about GemBox.Document and GemBox Software.