0

I am trying to add placeholders to my slide using python pptx. But the place holders always end up in the top left of the slide and comes up as size 0. I think this may be something to do with the placeholder not being defined in the layout? Is it possible to provide the position and size of the placeholder?

I used the below lines when trying to add a placeholder:

chart_pp = pptx.shapes.placeholder.PP_PLACEHOLDER.CHART
slide.shapes.placeholders.element.add_placeholder(id_ = 2, name = "chart",     
ph_type=chart_pp, orient = "horz", sz= "full", idx = 9)
user4029
  • 1
  • 4
  • Could you not use the `top`, `left`, `width` and `height` properties of the placeholder object to give it the desired position and size? – 0liveradam8 Dec 19 '17 at 22:40

1 Answers1

1

Did you consult the documentation? Your code is not close to being valid intended usage.

In any case, actual placeholder objects can only be present on a slide layout. So what you're trying to do is not a valid PowerPoint "thing".

A shape referring to each layout placeholder object is added to a slide when it is created from that layout. There's no way to add a placeholder to a slide, only for a shape to "inherit" from one that exists on the slide layout.

The .element attribute on any API object (like .placeholders for instance) is a reference to the underlying XML element. All bets are off when you access that and you can cause all kinds of breakage in the document if you don't understand what you're doing. It's there for those who are willing to undertake learning the XML schema and manipulate it to implement features not in python-pptx yet.

scanny
  • 26,423
  • 5
  • 54
  • 80