Skip to content

support adding slide_layout - #1091

Open
wkpark wants to merge 2 commits into
scanny:masterfrom
wkpark:slidelayout
Open

support adding slide_layout#1091
wkpark wants to merge 2 commits into
scanny:masterfrom
wkpark:slidelayout

Conversation

@wkpark

@wkpark wkpark commented Oct 10, 2025

Copy link
Copy Markdown

WIP

This is merely one example.

It does not function perfectly, and only some features work as intended.
Nevertheless, if you are planning to add or edit slide layouts, please refer to this.

  • add_layout()
  • add_placeholder()

#1044 - apply this suggestion into this PR.

examples

...
    prs = Presentation()
    ph_list = [
        PP_PLACEHOLDER.TITLE,
        PP_PLACEHOLDER.CENTER_TITLE
        PP_PLACEHOLDER.SUBTITLE,
        PP_PLACEHOLDER.BODY,
    ]
...
    layout= prs.slide_layouts.add_layout("My Layout %s")
...
    ph = layout.shapes.add_placeholder(PP_PLACEHOLDER.TITLE, "horz", "full")
    ph.text = "insert Title here"
...

lofcz added a commit to lofcz/python-pptx2 that referenced this pull request Aug 30, 2026
SlideLayouts.add_layout(name="Layout %s") appends a blank layout to a
slide master, and SlideLayouts.clone(layout) deep-copies an existing
layout of the same presentation under a non-colliding name. Both are
usable with prs.slides.add_slide(), register a fresh presentation-
unique p:sldLayoutId (max+1 over 2147483648), and pair with
LayoutShapes.add_placeholder(), whose idx defaults to the matching
master placeholder so inheritance and shapes.title keep working. The
clone path reuses the _slide_importer utilities (_clone_xml_part,
_remap_rids, and next_layout_hierarchy_id, extracted from
_SlideImporter._next_hierarchy_id) so images and external links a
layout refers to survive with remapped rIds.

Port of scanny#1091 by wkpark.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant