Bob
Bob

Reputation: 1396

Changing PowerPoint Text Frame Size

I'm trying to change the size of a text_frame to match the size of the PowerPoint slide I'm automating the creation of. I've found that I can change the slide width and slide height via...

prs=Presentation()
prs.slide_width = Inches(16)
prs.slide_height = Inches(9)

And title shape via...

title_shape = shapes.title
title_shape.width = Inches(16)
title_shape.height = Inches(2)

but this method doesn't have any effect on the text_frame using the following code...

        slide = prs.slides.add_slide(bullet_slide_layout)
        shapes = slide.shapes
        title_shape = shapes.title
        title_shape.width = Inches(16)
        title_shape.height = Inches(2)
        body_shape = shapes.placeholders[1]
        title_shape.text = project['name']
        tf = body_shape.text_frame
        tf.text = ""
        tf.width = Inches(16)
        tf.height = Inches(9)

I thought the tf.width and tf.height would do the trick, but it's not working for me. Any ideas?

Upvotes: 0

Views: 1555

Answers (1)

scanny
scanny

Reputation: 28893

The things on a PowerPoint slide that have size are shapes. The title-placeholder is a shape (basically a textbox shape) and so is the body placeholder.

So to change its size you assign to the shape's width and height properties:

body_shape = shapes.placeholders[1]
body_shape.width = Inches(16)
body_shape.height = Inches(9)

Certain shapes (the geometric ones called autoshapes) can contain text. Other shapes like picture shapes can't. When a shape can contain text, the shape has a .text_frame property that is the "container" of the text for the shape and controls certain aspects of how it is formatted, like whether it wraps etc.

But the text-frame does not have a size, per se; how big the text-frame appears is determined by the size of the shape it belongs to and to a certain degree the wrap settings and how much text is in it.

Upvotes: 1

Related Questions