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 : IPortion

Constructors

SignatureDescription
Portion()Create an empty portion.
Portion(string text)Create a portion with the specified text.

Properties

PropertyTypeAccessDescription
TextstringReadThe text content of this portion.
PortionFormatIBasePortionFormat?ReadCharacter-level formatting for this portion.
SlideIBaseSlide?ReadSlide containing this portion.
PresentationIPresentation?ReadParent presentation.

PortionFormat Properties (via BasePortionFormat)

Key properties available on PortionFormat:

PropertyTypeDescription
LatinFontIFontData?Latin font face.
EastAsianFontIFontData?East Asian font face.
ComplexScriptFontIFontData?Complex script font face.
FontHeightfloatFont size in points.
FontBoldNullableBoolBold flag.
FontItalicNullableBoolItalic flag.
FontUnderlineTextUnderlineTypeUnderline style.
StrikethroughTypeTextStrikethroughTypeStrikethrough style.
TextCapTypeTextCapTypeCapitalization style.
EscapementfloatSuperscript/subscript offset.
SpacingfloatCharacter spacing.
KerningMinimalSizefloatMinimum font size for kerning.
FillFormatIFillFormat?Text fill settings.
HighlightColorIColorFormat?Text highlight color.
LanguageIdstring?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}");
        }
    }
}

See Also