You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using python-pptx to populate a template, mostly with long decimal numbers, and fit_text runs into some problems when called on TextFrames with long strings that can't be broken up; it looks like it happens in the part of the library that calculates the text that can fit on the current line and the remainder.
If you use a PowerPoint template similar to the attached image, the following script reproduces the problem:
frompptximportPresentationdefget_target_shape(slide, name):
forshapeinslide.shapes:
ifshape.name==name:
returnshaperaiseException("Shape '{0}' not found in slide {1}"
.format(name, slide.name))
defset_autofit(shape):
text_frame=shape.text_frameforparagraphintext_frame.paragraphs:
paragraph.font.name="Calibri"text_frame.fit_text(font_file=r"c:\windows\fonts\calibriz.ttf")
if__name__=="__main__":
ppt=Presentation("template.pptx")
slide=ppt.slides[0]
shape=get_target_shape(slide, "Oval 3")
# This works, although the font size is still too big:shape.text="this string is too long and needs to be resized"# This crashes:#shape.text = "thisstringistoolongandneedstoberesized"# This also crashes:#shape.text = "thisstring is toolong and needs toberesized"set_autofit(shape)
ppt.save("template_populated.pptx")
(oops, attachments don't seem to work - template.pptx is a single slide containing an oval autoshape with dimensions H: 0.75", W: 1")
The text was updated successfully, but these errors were encountered:
I realize this feature is still under development and has some constraints (as per https://python-pptx.readthedocs.org/en/latest/dev/analysis/features/txt-fit-text.html) --
I'm using python-pptx to populate a template, mostly with long decimal numbers, and fit_text runs into some problems when called on TextFrames with long strings that can't be broken up; it looks like it happens in the part of the library that calculates the text that can fit on the current line and the remainder.
If you use a PowerPoint template similar to the attached image, the following script reproduces the problem:
(oops, attachments don't seem to work - template.pptx is a single slide containing an oval autoshape with dimensions H: 0.75", W: 1")
The text was updated successfully, but these errors were encountered: