PowerPoint Paragraph Formatting in C# and VB.NET

When building presentations, formatting paragraphs is essential for better visibility and readability. All the textual content in paragraphs can be inserted in text boxes or even shapes.

GemBox.Presentation supports TextParagraphFormat options like alignment, indentation, spacing and many others. You can use it to edit your presentations programmatically in C# and VB.NET.

The following example shows some of the available paragraph-formatting options and how to insert them into your PowerPoint files.

PowerPoint paragraphs formatted with GemBox.Presentation
Screenshot of PowerPoint paragraphs formatted with GemBox.Presentation
using GemBox.Presentation;

class Program
{
    static void Main()
    {
        // If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = new PresentationDocument();

        // Create new slide.
        var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

        // Create new text box.
        var textBox = slide.Content.AddTextBox(
            ShapeGeometryType.RoundedRectangle, 2, 2, 10, 4, LengthUnit.Centimeter);

        // Create new paragraph.
        var paragraph = textBox.AddParagraph();

        // Set paragraph text.
        paragraph.AddRun("This paragraph has the following properties: alignment is justify, after spacing is 100% of the text size, before spacing is 250% of the text size, line spacing is 200% of the text size.");

        // Set selected paragraph format.
        var format = paragraph.Format;
        format.Alignment = HorizontalAlignment.Justify;
        format.SpacingAfter = TextSpacing.Single;
        format.SpacingBefore = TextSpacing.Multiple(2.5);
        format.SpacingLine = TextSpacing.Double;

        // Create new paragraph.
        paragraph = textBox.AddParagraph();

        // Set paragraph text.
        paragraph.AddRun("This paragraph has the following properties: alignment is left, indentation before text is 15 points and first line indentation is 25 points.");

        // Set selected paragraph format.
        paragraph.Format.Alignment = HorizontalAlignment.Left;
        paragraph.Format.IndentationBeforeText = Length.From(15, LengthUnit.Point);
        paragraph.Format.IndentationSpecial = Length.From(25, LengthUnit.Point);

        presentation.Save("Paragraph Formatting.%OutputFileType%");
    }
}
Imports GemBox.Presentation

Module Program

    Sub Main()

        ' If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim presentation = New PresentationDocument

        ' Create New slide.
        Dim slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        ' Create New text box.
        Dim textBox = slide.Content.AddTextBox(
            ShapeGeometryType.RoundedRectangle, 2, 2, 10, 4, LengthUnit.Centimeter)

        ' Create New paragraph.
        Dim paragraph = textBox.AddParagraph()

        ' Set paragraph text.
        paragraph.AddRun("This paragraph has the following properties: alignment is justify, after spacing is 100% of the text size, before spacing is 250% of the text size, line spacing is 200% of the text size.")

        ' Set selected paragraph format.
        Dim format = paragraph.Format
        format.Alignment = HorizontalAlignment.Justify
        format.SpacingAfter = TextSpacing.Single
        format.SpacingBefore = TextSpacing.Multiple(2.5)
        format.SpacingLine = TextSpacing.Double

        ' Create New paragraph.
        paragraph = textBox.AddParagraph()

        ' Set paragraph text.
        paragraph.AddRun("This paragraph has the following properties: alignment is left, indentation before text is 15 points and first line indentation is 25 points.")

        ' Set selected paragraph format.
        paragraph.Format.Alignment = HorizontalAlignment.Left
        paragraph.Format.IndentationBeforeText = Length.From(15, LengthUnit.Point)
        paragraph.Format.IndentationSpecial = Length.From(25, LengthUnit.Point)

        presentation.Save("Paragraph Formatting.%OutputFileType%")
    End Sub
End Module

See also


Next steps

GemBox.Presentation is a .NET component that enables you to read, write, edit, convert, and print presentation files from your .NET applications using one simple API.

Download Buy