3

I'm working with pptx-python and i want to set the default size of an slide to the panoramic size (16:9). By now i can only create slides with a size of 4:3, the default one. How can i change the size of a slide?

I tried by accessing to width an height attributes of the slide, but the object Slide doesn't have any of those attributes.

   presentation = Presentation()
   title_only_slide_layout = presentation.slide_layouts[5]
   slide = presentation.slides.add_slide(title_only_slide_layout)
   print(slide.height)

AttributeError: 'SlideShapes' object has no attribute 'height'

cilopez
  • 75
  • 2
  • 9

1 Answers1

3

The documentation found here python-pptx Documentation states that the "Presentation" object has the attribute "slide_height", but I did not see any documentation on "Slide" objects having the attribute height. Instead, it seems that the "Slide" inherits the height and width from "Presentation".

Try changing your print statement to the following.

print(presentation.slide_height)
jdpy19
  • 375
  • 1
  • 13
  • 2
    Thanks , now i can change the size of the slide with the next code ```python presentation = Presentation() presentation.slide_height = Inches(9) presentation.slide_width = Inches(16) ``` – cilopez Oct 16 '19 at 15:13
  • You should also consider just starting with a 16x9 template file of your choosing, which avoids other problems with slide layouts and so forth: `prs = Presentation("my-blank-16x9-deck.pptx")`. You can create one of these from a 16x9 PPTX file by deleting all the slides and saving it. – scanny Oct 16 '19 at 16:38