Open darsh10 opened 3 years ago
You can't, at least not very reliably and not easily. What you can do is set the shape autofit setting to not resize to fit text and not to wrap. Then the shape should stay its original size. The reason you see different behavior is that Keynote and Google Slides refresh the shape wrapping/autosize on load whereas PowerPoint does not (until you adjust the shape in the smallest way).
The properties that control these behaviors are on the TextFrame
object accessed via shape.text_frame
and documented here: https://python-pptx.readthedocs.io/en/latest/api/text.html#text-related-objects.
Hi Scanny,
Thanks a lot for the pointer. I have gone through this documentation. I was curious to learn if there is a way for us to identify the overflow. I do see the text in the original size. Just want to detect the cases when there is an overflow automatically.
Ah, right, I see now better what you're after. Well, the problem is we have no access to the rendering engine and approximating its text layout behavior is beyond the capabilities of standard Python packages (like PIL) last time I looked, which was when the TextFrame.fit_text()
method was written. Maybe things have come along since then. Probably a direct-access-to-PowerPoint-application API like Visual Basic (VBA) or the win32com interface (Windows only) would have access to the rendering engine somehow and be able to tell you at least something about when the text was too wide. Maybe Qt or some package like that has better font-metrics discovery and could do better than we were able to with PIL a few years back.
It has occurred to me that one could write VBA or (in my case) AppleScript to post-process the .pptx made by python-pptx.
(In my md2pptx project - based on python-pptx - I'm thinking of allowing a post-processing exit point. I've not found a good case for doing so - and I'm not sure your need is it.)
Hi python-pptx,
I have created a rectangle shape in my powerpoint with a fixed size. There is text written inside the shape. However, the text is long and it overflows. This is expected. When I open the slide in keynote or google slides, the text has a larger text box. I would like to understand how I can programmatically identify the locations where the text overflows.
Thank you, Darsh.