TextFrame — Aspose.Slides FOSS for .NET API Reference

The TextFrame class holds the text content of a shape or table cell. It exposes paragraphs (each containing portions of formatted text) and frame-level formatting such as margins, anchoring, and autofit.

Package: Aspose.Slides.Foss (net9.0)

using Aspose.Slides.Foss;
public class TextFrame : ISlideComponent, ITextFrame

Properties

PropertyTypeAccessDescription
ParagraphsIParagraphCollectionReadCollection of paragraphs in the text frame.
TextstringReadConcatenated text of all paragraphs.
TextFrameFormatITextFrameFormatReadFrame-level formatting (margins, autofit, columns).
ParentShapeIShape?ReadShape that owns this text frame.
ParentCellICell?ReadTable cell that owns this text frame, if applicable.
SlideIBaseSlide?ReadSlide containing this text frame.
PresentationIPresentation?ReadParent presentation.

Usage Examples

Read Text from a Shape

using Aspose.Slides.Foss;

using var prs = new Presentation("deck.pptx");
foreach (var slide in prs.Slides)
{
    foreach (var shape in slide.Shapes)
    {
        if (shape is IAutoShape auto && auto.TextFrame != null)
        {
            Console.WriteLine(auto.TextFrame.Text);
        }
    }
}

Add Paragraphs and 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 paragraph";

var para = new Paragraph();
para.Portions.Add(new Portion("Second paragraph"));
tf.Paragraphs.Add(para);

prs.Save("text.pptx", SaveFormat.Pptx);

Adjust Text Frame Formatting

using Aspose.Slides.Foss;

using var prs = new Presentation();
var shape = prs.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 300, 150);
shape.AddTextFrame("Centered text");

var fmt = shape.TextFrame.TextFrameFormat;
Console.WriteLine($"Autofit: {fmt.AutofitType}");
Console.WriteLine($"Anchor: {fmt.AnchoringType}");

See Also