Paragraph, ParagraphCollection, ParagraphFormat, BulletFormat — Aspose.Slides FOSS for Python API Reference

A Paragraph is a block of text inside a TextFrame. Each paragraph owns a collection of Portion objects (character runs) and a ParagraphFormat that controls alignment, spacing, indentation, and bullets.

Package: aspose.slides_foss


Paragraph

Access via text_frame.paragraphs[i] or instantiate directly with Paragraph() to build new content.

Constructor

from aspose.slides_foss import Paragraph

para = Paragraph()   # Creates a detached paragraph with an empty <a:p> element.

Properties

PropertyTypeAccessDescription
textstrRead/WritePlain text of all portions joined. Setting this replaces all portions with a single run.
portionsPortionCollectionReadOrdered collection of Portion objects.
paragraph_formatParagraphFormatReadParagraph-level formatting (alignment, spacing, indent, bullet).
slideIBaseSlideReadThe slide that contains this paragraph.
presentationIPresentationReadThe presentation that contains this paragraph.

ParagraphCollection

Collection of Paragraph objects inside a TextFrame. Access via text_frame.paragraphs.

MemberSignatureDescription
addadd(paragraph)Append a Paragraph to the end of the text frame.
insertinsert(index, paragraph)Insert a Paragraph at the given zero-based index.
remove_atremove_at(index)Remove the paragraph at the given index.
clearclear()Remove all paragraphs.
__getitem__paragraphs[i]Return the paragraph at zero-based index i.
__len__len(paragraphs)Number of paragraphs.
__iter__for p in paragraphsIterate paragraphs in order.

ParagraphFormat

Controls paragraph-level layout. Access via paragraph.paragraph_format.

All properties support NaN (Python float('nan')) to mean “not defined / inherit from parent”.

Alignment

PropertyTypeDescription
alignmentTextAlignmentHorizontal alignment: LEFT, CENTER, RIGHT, JUSTIFY, JUSTIFY_LOW, DISTRIBUTED, or NOT_DEFINED.
font_alignmentFontAlignmentVertical position of characters within a line: AUTOMATIC, TOP, CENTER, BOTTOM, BASELINE.

Spacing

PropertyTypeDescription
space_withinfloatLine spacing. Positive value = percentage of font size; negative = points. NaN = inherit.
space_beforefloatSpace before the paragraph. Positive = % of font size; negative = points. NaN = inherit.
space_afterfloatSpace after the paragraph. Same encoding as space_before.

Indentation

PropertyTypeDescription
margin_leftfloatLeft margin in points. NaN = inherit.
margin_rightfloatRight margin in points.
indentfloatFirst-line or hanging indent in points. Negative = hanging.
default_tab_sizefloatDefault tab stop size in points.
depthintOutline level / list depth (0 = top level).

Flags (NullableBool)

PropertyDescription
east_asian_line_breakEast Asian line-break rules.
right_to_leftRight-to-left paragraph writing direction.
latin_line_breakLatin line-break rules.
hanging_punctuationAllow punctuation to hang beyond the margin.

Bullet and Default Format

PropertyTypeDescription
bulletBulletFormatBullet and numbering settings for this paragraph.
default_portion_formatPortionFormatDefault character formatting applied when a portion has no explicit format.

BulletFormat

Access via paragraph.paragraph_format.bullet.

PropertyTypeDescription
typeBulletTypeNONE, SYMBOL, NUMBERED, PICTURE.
charstrBullet character when type = SYMBOL.
colorColorFormatBullet colour.
fontFontDataBullet font.
font_heightfloatBullet size as a percentage of the text size (e.g., 100.0).
numbered_bullet_styleNumberedBulletStyleNumbering style when type = NUMBERED.
numbered_bullet_start_withintStarting number for a numbered list.
is_bullet_hard_colorNullableBoolWhether the bullet uses an explicit colour rather than inheriting from the text.
is_bullet_hard_fontNullableBoolWhether the bullet uses an explicit font rather than inheriting.

Usage Example

Multi-level bulleted list

import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, Paragraph, Portion, TextAlignment
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, 50, 500, 300)
    tf = shape.add_text_frame("")

    # Clear auto-created paragraph
    tf.paragraphs.clear()

    items = [("Introduction", 0), ("Background", 1), ("Scope", 1), ("Objectives", 0)]
    for text, level in items:
        para = Paragraph()
        portion = Portion()
        portion.text = text
        para.portions.add(portion)
        pf = para.paragraph_format
        pf.depth = level
        pf.space_before = -6.0   # 6 pt before each item
        tf.paragraphs.add(para)

    prs.save("bullets.pptx", SaveFormat.PPTX)

Justified text with custom line spacing

import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, TextAlignment
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, 50, 500, 200)
    tf = shape.add_text_frame("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
    pf = tf.paragraphs[0].paragraph_format
    pf.alignment = TextAlignment.JUSTIFY
    pf.space_within = 150.0   # 150% line spacing
    prs.save("justified.pptx", SaveFormat.PPTX)

See Also