Paragraph — Aspose.Slides FOSS for .NET API Reference
The Paragraph class represents a single paragraph inside a TextFrame. Each paragraph contains one or more Portion objects (runs of uniformly formatted text) and has its own ParagraphFormat controlling alignment, spacing, indentation, and bullets.
Package: Aspose.Slides.Foss (net9.0)
using Aspose.Slides.Foss;public class Paragraph : IParagraphConstructors
| Signature | Description |
|---|---|
Paragraph() | Create a new empty paragraph. |
Properties
| Property | Type | Access | Description |
|---|---|---|---|
Portions | IPortionCollection | Read | Collection of text portions in this paragraph. |
ParagraphFormat | IParagraphFormat | Read | Paragraph-level formatting (alignment, spacing, bullets). |
Text | string | Read | Concatenated text of all portions. |
Slide | IBaseSlide? | Read | Slide containing this paragraph. |
Presentation | IPresentation? | Read | Parent presentation. |
ParagraphFormat Properties
The IParagraphFormat object exposed by ParagraphFormat includes:
| Property | Type | Description |
|---|---|---|
Alignment | TextAlignment | Horizontal text alignment. |
SpaceWithin | float | Line spacing within the paragraph. |
SpaceBefore | float | Space before the paragraph. |
SpaceAfter | float | Space after the paragraph. |
Indent | float | First-line indent. |
MarginLeft | float | Left margin. |
MarginRight | float | Right margin. |
Depth | int | Outline/indentation depth level. |
Bullet | IBulletFormat | Bullet settings. |
DefaultPortionFormat | PortionFormat | Default formatting for new portions. |
RightToLeft | NullableBool | Right-to-left text direction. |
FontAlignment | FontAlignment | Vertical font alignment. |
Usage Examples
Create Paragraphs with Portions
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var shape = prs.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 400, 200);
shape.AddTextFrame("");
var tf = shape.TextFrame;
tf.Paragraphs[0].Portions[0].Text = "First line";
var p2 = new Paragraph();
p2.Portions.Add(new Portion("Second line"));
tf.Paragraphs.Add(p2);
prs.Save("paragraphs.pptx", SaveFormat.Pptx);Read Paragraph Formatting
using Aspose.Slides.Foss;
using var prs = new Presentation("deck.pptx");
var shape = prs.Slides[0].Shapes[0] as IAutoShape;
if (shape?.TextFrame != null)
{
foreach (var para in shape.TextFrame.Paragraphs)
{
Console.WriteLine($"Text: {para.Text}");
Console.WriteLine($" Alignment: {para.ParagraphFormat.Alignment}");
Console.WriteLine($" Depth: {para.ParagraphFormat.Depth}");
}
}