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
SystemObject
  SautinSoft.DocumentFormat
    SautinSoft.DocumentParagraphFormat

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

The ParagraphFormat type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleParagraphFormat Initializes a new instance of ParagraphFormat class.
Top
Properties
 NameDescription
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 propertyCode exampleLeftIndentation Gets or sets the value (in points) that represents the left indent for paragraph.
Public propertyCode exampleLineSpacing 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 propertyCode exampleOutlineLevel Gets or sets the outline level of the paragraph.
Public propertyCode examplePageBreakBefore When true, this paragraph is rendered on the start of a new page in the document.
Public propertyCode exampleRightIndentation 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 propertyCode exampleSpecialIndentation 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.
Top
Methods
 NameDescription
Public methodCode exampleClearFormatting 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))
Top
Example

See Developer Guide: This sample shows how to specify a paragraph formatting

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)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            ParagraphFormatting();
        }

        /// <summary>
        /// This sample shows how to specify a paragraph formatting. 
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/paragraph-format.php
        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);
            dc.Sections.Add(s);

            // Paragraph 1.
            Paragraph p = new Paragraph(dc, "First paragraph!");
            dc.Sections[0].Blocks.Add(p);

            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));
                dc.Sections[0].Blocks.Add(pN);

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

                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.
            dc.Save(documentPath);

            // 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()
        ParagraphFormatting()
    End Sub
    ''' Get your free 30-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' This sample shows how to specify a paragraph formatting. 
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/paragraph-format.php
    ''' </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)
        dc.Sections.Add(s)

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

        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))
            dc.Sections(0).Blocks.Add(pN)

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

            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.
        dc.Save(documentPath)

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

End Module
See Also