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, ITextFrameProperties
| Property | Type | Access | Description |
|---|---|---|---|
Paragraphs | IParagraphCollection | Read | Collection of paragraphs in the text frame. |
Text | string | Read | Concatenated text of all paragraphs. |
TextFrameFormat | ITextFrameFormat | Read | Frame-level formatting (margins, autofit, columns). |
ParentShape | IShape? | Read | Shape that owns this text frame. |
ParentCell | ICell? | Read | Table cell that owns this text frame, if applicable. |
Slide | IBaseSlide? | Read | Slide containing this text frame. |
Presentation | IPresentation? | Read | Parent 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}");