Presentation — Aspose.Slides FOSS for Python API Reference

The Presentation class is the root object for creating, loading, and saving PowerPoint .pptx files in aspose-slides-foss.

Package: aspose.slides_foss

import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

Constructor

slides.Presentation(source=None, load_options=None)
ParameterTypeDescription
sourcestr | BinaryIO | NoneFile path or binary stream for an existing .pptx file. Pass None (or omit) to create a new empty presentation with one blank slide.
load_optionsLoadOptions | NoneOptional load options (e.g., password).

Examples:

import aspose.slides_foss as slides

# Create a new empty presentation
prs = slides.Presentation()

# Open an existing PPTX file
prs = slides.Presentation("deck.pptx")

# Load from a binary stream
import io
with open("deck.pptx", "rb") as f:
    stream = io.BytesIO(f.read())
prs = slides.Presentation(stream)

The class supports the context manager protocol. Use with to ensure the presentation is closed properly:

import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation("input.pptx") as prs:
    print(f"Slide count: {len(prs.slides)}")
    prs.save("output.pptx", SaveFormat.PPTX)

Properties

PropertyTypeAccessDescription
slidesSlideCollectionReadOrdered collection of slides. Access by zero-based index: prs.slides[0].
master_slidesMasterSlideCollectionReadCollection of master slides in the presentation.
layout_slidesGlobalLayoutSlideCollectionReadCollection of all layout slides across all masters.
comment_authorsCommentAuthorCollectionReadCollection of comment authors. Add authors via add_author().
document_propertiesDocumentPropertiesReadCore, application, and custom document metadata.
imagesImageCollectionReadCollection of all images embedded in the presentation.

Methods

save

prs.save(path, format)

Save the presentation to a file.

ParameterTypeDescription
pathstrDestination file path.
formatSaveFormatOutput format. Currently only SaveFormat.PPTX is supported.
from aspose.slides_foss.export import SaveFormat

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

dispose

prs.dispose()

Release resources. Called automatically when using the with statement.


SlideCollection Methods

MethodSignatureDescription
add_empty_slide(layout: LayoutSlide) -> SlideAppend a new empty slide using the given layout.
remove_at(index: int) -> NoneRemove the slide at zero-based index.
__getitem__[index: int] -> SlideReturn the slide at zero-based index.
__len__() -> intNumber of slides in the presentation.
__iter__N/AIterate over all slides.

Usage Examples

Create a Presentation with a Shape

import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType
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, 300, 100)
    shape.add_text_frame("Hello, Slides!")
    prs.save("hello.pptx", SaveFormat.PPTX)

Open, Inspect, and Re-Save

import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation("existing.pptx") as prs:
    print(f"Slides: {len(prs.slides)}")
    for i, slide in enumerate(prs.slides):
        print(f"  Slide {i}: {len(slide.shapes)} shapes")
    prs.save("existing-updated.pptx", SaveFormat.PPTX)

Set Document Properties

import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    prs.document_properties.title = "Q1 Results"
    prs.document_properties.author = "Finance Team"
    prs.document_properties.subject = "Quarterly Review"
    prs.document_properties.set_custom_property_value("Version", 3)
    prs.save("q1.pptx", SaveFormat.PPTX)

Add Comments

from aspose.slides_foss.drawing import PointF
from datetime import datetime
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat

with slides.Presentation() as prs:
    author = prs.comment_authors.add_author("Jane Smith", "JS")
    slide = prs.slides[0]
    author.comments.add_comment(
        "Please review this slide",
        slide,
        PointF(2.0, 2.0),
        datetime.now()
    )
    prs.save("commented.pptx", SaveFormat.PPTX)

Limitations

The following features raise NotImplementedError in this version:

  • Charts, SmartArt, OLE objects
  • Animations and slide transitions
  • Export formats other than PPTX (PDF, HTML, images)
  • Hyperlinks and action settings
  • VBA macros and digital signatures

Unknown XML parts in an existing PPTX file are preserved verbatim on save.


See Also