auto_size not working
xlar8or opened this issue · comments
Hello, I'm creating a textbox and I want it to be sized so it fits the whole text in the TextFrame. I'm doing the following code:
textbox = slide.shapes.add_textbox(0, 0, Inches(3), Inches(1))
text_frame = textbox.text_frame
text_frame.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
text_frame.auto_size = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT
text_frame.word_wrap = True
This is what I get:
If i go to the Textbox properties I have the following:
If I click again on the Resize shape to fit text then I get the correct behavior:
FYI: I don't have PowerPoint, I'm using WPS, could that contribute to the problem?
The problem is not because of WPS.
Auto sizing font to fit the textbox is not easy. There is an experimental feature fit_text()
but it doesn't always work. To learn more read this: https://python-pptx.readthedocs.io/en/latest/dev/analysis/txt-autofit-text.html?highlight=auto%20fit
Closing as not actionable. @xlar8or there is unlikely to be further work on auto_size and it entails partially implementing a renderer with is out-of-scope on principle for this library.