scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.26k stars 498 forks source link

How to set shink in sharp when text box overflow in Python pptx #969

Open MichaelPanwenjie opened 2 months ago

MichaelPanwenjie commented 2 months ago

How to set indentation when text box overflow in Python pptx, my codes is here: def set_shrink_text_on_overflow(shape): import pptx print(pptx.version) if shape.has_text_frame: text_frame = shape.text_frame try:

text_frame.fit_text(max_size=18)

        # text_frame.auto_size = MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE
        # text_frame.word_wrap = True
        text_frame.auto_size = MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE
        text_frame.word_wrap = True
        # time.sleep(0.5)          
    except Exception as e:
        print(e)
        pass

the codes setting correctlly but the ppt file still remain overflow,it should open ppt file manual,i want do it automatically Can anyone can find the solution?

MichaelPanwenjie commented 2 months ago

Continuing with the previous topic, why did you set text indentation but not respond? You need to manually trigger the rendering engine. The reason is that the settings were modified to a ppt file, and the corresponding options were set correctly. However, there is still a missing attribute fontScale like . After manually triggering the rendering engine, a new attribute,, was added to the corresponding XML file structure. The value of X is a scaled value that is not fixed, so it is necessary to add this attribute to automatically indent.

The author can consider this point by adding this attribute to the 'resize text to fit shape' setting in Python pptx. Correct X, thank you. Looking forward to the author's response and revisions