Portion, PortionCollection — Aspose.Slides FOSS for Python API Reference

A Portion is the smallest independently-formatted unit of text. Every Paragraph contains one or more Portion objects; each portion carries its own PortionFormat (font size, bold, colour, etc.).

Package: aspose.slides_foss


Portion

Constructor

from aspose.slides_foss import Portion

p = Portion()          # empty portion
p = Portion("Hello")   # portion pre-filled with text

Properties

PropertyTypeAccessDescription
textstrRead/WritePlain text content of this portion. Setting this writes to the underlying <a:t> element and persists immediately.
portion_formatPortionFormatReadCharacter-level formatting for this portion. All format properties are explicitly set (no inheritance applied).
slideIBaseSlideReadThe slide that contains this portion.
presentationIPresentationReadThe presentation that contains this portion.

PortionFormat

Access via portion.portion_format. All properties are explicitly setNOT_DEFINED means inherit from the parent paragraph’s default portion format.

Font Properties

PropertyTypeDescription
font_heightfloatFont size in points. NaN = inherit.
latin_fontFontDataWestern (Latin) typeface. Assign FontData("Arial").
east_asian_fontFontDataEast Asian typeface.
complex_script_fontFontDataComplex-script (RTL, Indic) typeface.

Style Flags (NullableBool)

PropertyDescription
font_boldBold. NullableBool.TRUE / FALSE / NOT_DEFINED.
font_italicItalic.
font_strike_throughStrikethrough (legacy alias).
font_capsAll-caps rendering.
font_small_capsSmall-caps rendering.

Underline

PropertyTypeDescription
font_underlineTextUnderlineTypeUnderline style: NONE, SINGLE, DOUBLE, HEAVY, DOTTED, etc.
underline_line_formatLineFormatLine format for the underline stroke.
underline_fill_formatFillFormatFill (colour) of the underline.

Strikethrough

PropertyTypeDescription
strikethrough_typeTextStrikethroughTypeNONE, SINGLE, DOUBLE.

Colour and Fill

PropertyTypeDescription
fill_formatFillFormatText fill. Set fill_type = FillType.SOLID and solid_fill_color.color to colour the text.
highlight_colorColorFormatText highlight/background colour.

Spacing

PropertyTypeDescription
spacingfloatCharacter spacing adjustment as a percentage of font size.
kerning_minimal_sizefloatMinimum font size at which kerning is applied, in points.

Baseline

PropertyTypeDescription
escapementintSuperscript/subscript offset as a percentage of the font height. Positive = superscript; negative = subscript.
baselineintSynonym for escapement (older API name).

Language

PropertyTypeDescription
language_idstrBCP 47 language tag (e.g. "en-US", "fr-FR").
alternative_language_idstrAlternative language for text rendering.

Hyperlink

PropertyTypeDescription
hyperlink_clickIHyperlinkClick hyperlink.
hyperlink_mouse_overIHyperlinkMouse-over hyperlink.
hyperlink_managerIHyperlinkManagerHelper object for adding and removing hyperlinks.

PortionCollection

Collection of Portion objects inside a Paragraph. Access via paragraph.portions.

MemberSignatureDescription
addadd(portion)Append a Portion to the end of the paragraph.
insertinsert(index, portion)Insert a Portion at the given zero-based index.
remove_atremove_at(index)Remove the portion at the given index.
clearclear()Remove all portions from the paragraph.
__getitem__portions[i]Return the portion at zero-based index i.
__len__len(portions)Number of portions.
__iter__for p in portionsIterate portions in order.

Usage Example

Mixed-format rich text in a single paragraph

import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, Portion, Paragraph, NullableBool, FillType
from aspose.slides_foss.drawing import Color
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    slide = prs.slides[0]
    shape = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 80, 560, 80)
    tf = shape.add_text_frame("")

    para = tf.paragraphs[0]
    para.portions.clear()

    # Plain portion
    p1 = Portion("Release ")
    para.portions.add(p1)

    # Bold version number
    p2 = Portion("2.4.0")
    p2.portion_format.font_bold = NullableBool.TRUE
    p2.portion_format.font_height = 20
    para.portions.add(p2)

    # Coloured suffix
    p3 = Portion(" — now available")
    p3.portion_format.fill_format.fill_type = FillType.SOLID
    p3.portion_format.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 112, 192)
    para.portions.add(p3)

    prs.save("mixed-format.pptx", SaveFormat.PPTX)

See Also