Click or drag to resize

ParagraphFormat Class

Represents a set of paragraph formatting properties which shall be applied to the contents of the parent paragraph.
Inheritance Hierarchy

Namespace:  SautinSoft.Document
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version:
public sealed class ParagraphFormat : Format

The ParagraphFormat type exposes the following members.

Public methodCode exampleParagraphFormat
Initializes a new instance of ParagraphFormat class.
Public propertyAfterAutospacing
When true, the amount of spacing after the paragraph is set automatically.
Public propertyCode exampleAlignment
Gets or sets the text alignment for the paragraph.
Public propertyCode exampleBackgroundColor
Gets or sets the paragraph background color.
Public propertyBeforeAutospacing
When true, the amount of spacing before the paragraph is set automatically.
Public propertyBorders
Gets collection of borders of the paragraph.
Public propertyKeepLinesTogether
When true, all lines for this paragraph are maintained on a single page whenever possible.
Public propertyKeepWithNext
When true, the paragraph is on the same page as the following paragraph whenever possible.
Public propertyLeftIndentation
Gets or sets the value (in points) that represents the left indent for paragraph.
Public propertyLineSpacing
Gets or sets the line spacing for the paragraph depending of LineSpacingRule.
Public propertyLineSpacingRule
Gets or sets the line spacing rule for the paragraph.
Public propertyMirrorIndents
Gets or sets whether the paragraph indents should be interpreted as mirrored indents.
Public propertyNoSpaceBetweenParagraphsOfSameStyle
When true, SpaceBefore and SpaceAfter will be ignored between the paragraphs of the same style.
Public propertyOutlineLevel
Gets or sets the outline level of the paragraph.
Public propertyPageBreakBefore
When true, this paragraph is rendered on the start of a new page in the document.
Public propertyRightIndentation
Gets or sets the value (in points) that represents the right indent for paragraph.
Public propertyRightToLeft
Gets or sets whether this is a right-to-left paragraph.
Public propertyCode exampleSpaceAfter
Gets or sets the amount of spacing (in points) after the paragraph.
Public propertyCode exampleSpaceBefore
Gets or sets the amount of spacing (in points) before the paragraph.
Public propertySpecialIndentation
Gets or sets the value (in points) for a first line or hanging indent. Use a positive value to set a first-line indent, and use a negative value to set a hanging indent.
Public propertyCode exampleStyle
Gets or sets the paragraph style.
Public propertyTabs
Gets collection of custom tab stops.
Public propertyWidowControl
When true, this will prevent a single line of the paragraph from being displayed on a separate page from the remaining content.
Public methodClearFormatting
Clears the formatting.
(Overrides FormatClearFormatting.)
Public methodClone
Clones this ParagraphFormat instance.
Public methodEquals
Determines whether the specified object is equal to this ParagraphFormat instance.
(Overrides ObjectEquals(Object).)
This sample shows how to specify a paragraph formatting in C#
using System;
using SautinSoft.Document;

namespace Sample
    class Sample

        static void Main(string[] args)

        /// <summary>
        /// This sample shows how to specify a paragraph formatting. 
        /// </summary>
        /// <remarks>
        /// Details:
        public static void ParagraphFormatting()
            string documentPath = @"ParagraphFormatting.docx";

            // Let's create a simple document.
            DocumentCore dc = new DocumentCore();

            // Add new section
            Section s = new Section(dc);

            // Paragraph 1.
            Paragraph p = new Paragraph(dc, "First paragraph!");

            p.ParagraphFormat.Alignment = HorizontalAlignment.Left;
            p.ParagraphFormat.SpaceAfter = 20.0;
            p.ParagraphFormat.Borders.Add(MultipleBorderTypes.All, BorderStyle.Single, Color.Orange, 2f);

            // Paragraph 2.
            dc.Content.End.Insert("\nThis is a second paragraph.", new CharacterFormat() { FontName = "Calibri", Size = 16.0, FontColor = Color.Black, Bold = true });
            (dc.Sections[0].Blocks[1] as Paragraph).ParagraphFormat.Alignment = HorizontalAlignment.Center;

            // Create multiple paragraphs.
            for (int i = 0; i < 10; i++)
                Paragraph pN = new Paragraph(dc, String.Format("Paragraph {0}. ", i + 1));

                pN.Content.End.Insert(new SpecialCharacter(dc, SpecialCharacterType.Tab).Content);
                Run run = new Run(dc, "Hello!");
                run.CharacterFormat.FontColor = Color.White;

                pN.ParagraphFormat.BackgroundColor = new Color((int)(0xFF358CCB * (i + 1)));
                pN.ParagraphFormat.SpaceBefore = LengthUnitConverter.Convert(1, LengthUnit.Centimeter, LengthUnit.Point);
                pN.ParagraphFormat.SpaceAfter = LengthUnitConverter.Convert(10, LengthUnit.Millimeter, LengthUnit.Point);

            // Save our document into DOCX format.

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
This sample shows how to specify a paragraph formatting in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
    End Sub

    ''' <summary>
    ''' This sample shows how to specify a paragraph formatting. 
    ''' </summary>
    ''' <remarks>
    ''' Details:
    ''' </remarks>
    Sub ParagraphFormatting()
        Dim documentPath As String = "ParagraphFormatting.docx"

        ' Let's create a simple document.
        Dim dc As New DocumentCore()

        ' Add new section
        Dim s As New Section(dc)

        ' Paragraph 1.
        Dim p As New Paragraph(dc, "First paragraph!")

        p.ParagraphFormat.Alignment = HorizontalAlignment.Left
        p.ParagraphFormat.SpaceAfter = 20.0
        p.ParagraphFormat.Borders.Add(MultipleBorderTypes.All, BorderStyle.Single, Color.Orange, 2.0F)

        ' Paragraph 2.
        dc.Content.End.Insert(vbLf & "This is a second paragraph.", New CharacterFormat() With {
            .FontName = "Calibri",
            .Size = 16.0,
            .FontColor = Color.Black,
            .Bold = True
        TryCast(dc.Sections(0).Blocks(1), Paragraph).ParagraphFormat.Alignment = HorizontalAlignment.Center

        ' Create multiple paragraphs.
        For i As Integer = 0 To 9
            Dim pN As New Paragraph(dc, String.Format("Paragraph {0}. ", i + 1))

            pN.Content.End.Insert((New SpecialCharacter(dc, SpecialCharacterType.Tab)).Content)
            Dim run As New Run(dc, "Hello!")
            run.CharacterFormat.FontColor = Color.White

            pN.ParagraphFormat.BackgroundColor = New Color(CInt(&HFF358CCB * (i + 1)))
            pN.ParagraphFormat.SpaceBefore = LengthUnitConverter.Convert(1, LengthUnit.Centimeter, LengthUnit.Point)
            pN.ParagraphFormat.SpaceAfter = LengthUnitConverter.Convert(10, LengthUnit.Millimeter, LengthUnit.Point)
        Next i

        ' Save our document into DOCX format.

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
    End Sub

End Module
See Also