Umar.H
Umar.H

Reputation: 23099

editing the position of a shape in PowerPoint

from pptx import Presentation


prs = Presentation(my_file)
print(prs.slides[1].shape[0])
#out:
#<pptx.shapes.picture.Picture at 0x2295816cf98>

I need to loop through my shapes and assign a custom height, width and vertical position :

height = 7002000
width = 12193200

i have my height + width values which I can set via assignment prs.slides[1].shape[0].height = height

with a simple loop.

one thing I can't find is the attribute to set the shape's position on the page, chiefly the Vertical Position

my correct value is set to -0.16cm which I'm trying to replicate.

I thought it might be under left or top but my correct presentation returns a value of 0

enter image description here

Upvotes: 0

Views: 812

Answers (2)

Umar.H
Umar.H

Reputation: 23099

Found the answer finally - I had to use a combination of top and left on the shape attribute.

in my case I had to set my variables to

top = -57600
left = 0 

I then access the shape method

for slide in prs.slides:
   for shape in slide.shapes:
       shape.left = left
       shape.top = top

Upvotes: 0

scanny
scanny

Reputation: 29031

Note that you can use the provided convenience measurements like this:

from pptx.util import Cm

shape.left = Cm(5.5)

Which saves you doing the arithmetic to English Metric Units (EMU) yourself.

Upvotes: 1

Related Questions