Paragraph Formatting

GemBox.Presentation supports paragraph-formatting options like alignment, indentation, spacing and many others.

The following example shows some of the available paragraph-formatting options.

Screenshot
Paragraph Formatting Screenshot

See the full code below, use Run Example to execute.

using GemBox.Presentation;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        PresentationDocument presentation = new PresentationDocument();

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

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

        // Create new paragraph.
        TextParagraph 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.
        TextParagraphFormat 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.pptx");
    }
}
Imports GemBox.Presentation

Module Samples

    Sub Main()

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

        Dim presentation As PresentationDocument = New PresentationDocument

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

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

        ' Create New paragraph.
        Dim paragraph As TextParagraph = 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 As TextParagraphFormat = 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.pptx")

    End Sub

End Module