Portion — Aspose.Slides FOSS for .NET API Reference
The Portion class represents a run of text with uniform formatting inside a Paragraph. Formatting is controlled through the PortionFormat property, which inherits from BasePortionFormat.
Package: Aspose.Slides.Foss (net9.0)
using Aspose.Slides.Foss;public class Portion : IPortionConstructors
| Signature | Description |
|---|---|
Portion() | Create an empty portion. |
Portion(string text) | Create a portion with the specified text. |
Properties
| Property | Type | Access | Description |
|---|---|---|---|
Text | string | Read | The text content of this portion. |
PortionFormat | IBasePortionFormat? | Read | Character-level formatting for this portion. |
Slide | IBaseSlide? | Read | Slide containing this portion. |
Presentation | IPresentation? | Read | Parent presentation. |
PortionFormat Properties (via BasePortionFormat)
Key properties available on PortionFormat:
| Property | Type | Description |
|---|---|---|
LatinFont | IFontData? | Latin font face. |
EastAsianFont | IFontData? | East Asian font face. |
ComplexScriptFont | IFontData? | Complex script font face. |
FontHeight | float | Font size in points. |
FontBold | NullableBool | Bold flag. |
FontItalic | NullableBool | Italic flag. |
FontUnderline | TextUnderlineType | Underline style. |
StrikethroughType | TextStrikethroughType | Strikethrough style. |
TextCapType | TextCapType | Capitalization style. |
Escapement | float | Superscript/subscript offset. |
Spacing | float | Character spacing. |
KerningMinimalSize | float | Minimum font size for kerning. |
FillFormat | IFillFormat? | Text fill settings. |
HighlightColor | IColorFormat? | Text highlight color. |
LanguageId | string? | Proofing language. |
Usage Examples
Create Formatted Text
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, 100);
shape.AddTextFrame("");
var portion = shape.TextFrame.Paragraphs[0].Portions[0];
portion.Text = "Bold and large";
portion.PortionFormat.FontBold = NullableBool.True;
portion.PortionFormat.FontHeight = 24;
portion.PortionFormat.LatinFont = new FontData("Arial");
prs.Save("formatted.pptx", SaveFormat.Pptx);Read Portion 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)
{
foreach (var portion in para.Portions)
{
Console.WriteLine($"'{portion.Text}' — font: {portion.PortionFormat.LatinFont?.FontName}, size: {portion.PortionFormat.FontHeight}");
}
}
}