SourceFormat / SaveFormat

SourceFormat and SaveFormat — Aspose.Slides FOSS Python API Reference

Two enumerations control how a presentation is identified when loaded and how it is written when saved: SourceFormat (detected automatically on open) and SaveFormat (specified explicitly on save).


SourceFormat Enum

SourceFormat reports the file format from which a presentation was loaded. It is read-only and available via prs.source_format.

Import: from aspose.slides_foss import SourceFormat

MemberDescription
PPTXOpenXML .pptx / .pptm / .ppsx / .potx
PPTLegacy binary .ppt format
ODPOpenDocument Presentation .odp format

SaveFormat Enum

SaveFormat specifies the output format passed to prs.save().

Import: from aspose.slides_foss.export import SaveFormat

MemberDescription
PPTXOpenXML .pptx (the only supported save format in this release)

Presentation Format-Related Properties

The Presentation class exposes two properties related to format:

PropertyTypeAccessDescription
source_formatSourceFormatReadThe format from which this presentation was loaded.
first_slide_numberintRead/WriteThe one-based number of the first slide (default 1).

Code Examples

Detect the Source Format After Loading

import aspose.slides_foss as slides
from aspose.slides_foss import SourceFormat

with slides.Presentation("deck.pptx") as prs:
    fmt = prs.source_format
    if fmt == SourceFormat.PPTX:
        print("Loaded as PPTX")
    elif fmt == SourceFormat.PPT:
        print("Loaded as legacy PPT")
    elif fmt == SourceFormat.ODP:
        print("Loaded as ODP")

Save a Presentation as PPTX

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

with slides.Presentation() as prs:
    slide = prs.slides[0]
    slide.shapes.add_auto_shape(
        slides.ShapeType.RECTANGLE, 50, 50, 300, 100
    ).add_text_frame("Hello, world!")

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

Save to a Binary Stream

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

buffer = io.BytesIO()
with slides.Presentation() as prs:
    prs.save(buffer, SaveFormat.PPTX)

# buffer now contains the complete PPTX bytes
buffer.seek(0)
pptx_bytes = buffer.read()
print(f"PPTX size: {len(pptx_bytes)} bytes")

Change the First Slide Number

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

with slides.Presentation("deck.pptx") as prs:
    prs.first_slide_number = 5   # numbering starts at 5
    prs.save("deck-renumbered.pptx", SaveFormat.PPTX)

See Also