Paper Office
paper-pptxAPI referenceparts.slide

SlidePart

paper-pptx 0.2.0 API reference

Slide part. Corresponds to package files ppt/slides/slide[1-9][0-9]*.xml.

Attributes

blob

attributeblobbytes

bytes XML serialization of this part.

content_type

attributecontent_typestr

Content-type (MIME-type) of this part.

has_notes_slide

attributehas_notes_slide

Return True if this slide has a notes slide, False otherwise. A notes slide is created by the :attr:notes_slide property when one doesn't exist; use this property to test for a notes slide without the possible side-effect of creating one.

name

attributenamestr

Internal name of this slide.

notes_slide

attributenotes_slideNotesSlide

The NotesSlide instance associated with this slide.

If the slide does not have a notes slide, a new one is created. The same single instance is returned on each call.

package

attributepackagePackage

Package this part belongs to.

part

attributepart

This part.

This is part of the parent protocol, "children" of the document will not know the part that contains them so must ask their parent object. That chain of delegation ends here for child objects.

partname

attributepartnamePackURI

PackURI partname for this part, e.g. "/ppt/slides/slide1.xml".

rels

attributerels_Relationships

Collection of relationships from this part to other parts.

slide

attributeslide

The Slide object representing this slide part.

slide_id

attributeslide_idint

Return the slide identifier stored in the presentation part for this slide part.

slide_layout

attributeslide_layoutSlideLayout

SlideLayout object the slide in this part inherits appearance from.

Functions

add_chart_part

funcadd_chart_part(chart_type: XL_CHART_TYPE, chart_data: ChartData)

Return str rId of new ChartPart object containing chart of chart_type.

The chart depicts chart_data and is related to the slide contained in this part by rId.

paramchart_typeXL_CHART_TYPE
paramchart_dataChartData

add_embedded_ole_object_part

funcadd_embedded_ole_object_part(prog_id: PROG_ID | str, ole_object_file: str | IO[bytes])

Return rId of newly-added OLE-object part formed from ole_object_file.

paramprog_idPROG_ID | str
paramole_object_filestr | IO[bytes]

drop_rel

funcdrop_rel(rId: str) -> None

Remove relationship identified by rId if its reference count is under 2.

Relationships with a reference count of 0 are implicit relationships. Note that only XML parts can drop relationships.

paramrIdstr

Returns

None

get_image

funcget_image(rId: str) -> Image

Return an Image object containing the image related to this slide by rId.

Raises KeyError if no image is related by that id, which would generally indicate a corrupted .pptx file.

paramrIdstr

Returns

pptx.parts.image.Image

get_or_add_image_part

funcget_or_add_image_part(image_file: str | IO[bytes])

Return (image_part, rId) pair corresponding to image_file.

The returned ImagePart object contains the image in image_file and is related to this slide with the key rId. If either the image part or relationship already exists, they are reused, otherwise they are newly created.

paramimage_filestr | IO[bytes]

get_or_add_video_media_part

funcget_or_add_video_media_part(video: Video) -> tuple[str, str]

Return rIds for media and video relationships to media part.

A new MediaPart object is created if it does not already exist (such as would occur if the same video appeared more than once in a presentation). Two relationships to the media part are created, one each with MEDIA and VIDEO relationship types. The need for two appears to be for legacy support for an earlier (pre-Office 2010) PowerPoint media embedding strategy.

paramvideoVideo

Returns

tuple[str, str]

load

funcload(partname: PackURI, content_type: str, package: Package, blob: bytes)

Return instance of cls loaded with parsed XML from blob.

parampartnamePackURI
paramcontent_typestr
parampackagePackage
paramblobbytes

load_rels_from_xml

funcload_rels_from_xml(xml_rels: CT_Relationships, parts: dict[PackURI, Part]) -> None

load _Relationships for this part from xml_rels.

Part references are resolved using the parts dict that maps each partname to the loaded part with that partname. These relationships are loaded from a serialized package and so already have assigned rIds. This method is only used during package loading.

paramxml_relsCT_Relationships
parampartsdict[PackURI, Part]

Returns

None

new

funcnew(partname, package, slide_layout_part)

Return newly-created blank slide part.

The new slide-part has partname and a relationship to slide_layout_part.

parampartname
parampackage
paramslide_layout_part
funcpart_related_by(reltype: str) -> Part

Return (single) part having relationship to this package of reltype.

Raises KeyError if no such relationship is found and ValueError if more than one such relationship is found.

paramreltypestr

Returns

pptx.opc.package.Part

relate_to

funcrelate_to(target: Part | str, reltype: str, is_external: bool = False) -> str

Return rId key of relationship of reltype to target.

If such a relationship already exists, its rId is returned. Otherwise the relationship is added and its new rId returned.

paramtargetPart | str
paramreltypestr
paramis_externalbool
= False

Returns

str
funcrelated_part(rId: str) -> Part

Return related Part subtype identified by rId.

paramrIdstr

Returns

pptx.opc.package.Part

target_ref

functarget_ref(rId: str) -> str

Return URL contained in target ref of relationship identified by rId.

paramrIdstr

Returns

str

On this page