python-pptx: insert picture into content placeholder

穿精又带淫゛_ 提交于 2019-11-30 23:27:21

See the documentation on Understanding placeholders and Working with placeholders.

In brief, using something like this, you get the placeholder from the slide, then call insert_picture on the placeholder:

>>> prs = Presentation()
>>> slide = prs.slides.add_slide(prs.slide_layouts[8])
>>> placeholder = slide.placeholders[1]  # idx key, not position
>>> placeholder.name
'Picture Placeholder 2'
>>> placeholder.placeholder_format.type
PICTURE (18)
>>> picture = placeholder.insert_picture('my-image.png')

Note that this only works with a picture placeholder. You'll need to replace any "general purpose" content placeholder with one specific to what you're going to insert.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!