首页 > 解决方案 > 如何在 python-docx 中将图片添加到页眉/页脚

问题描述

我想使用 python-docx 在页脚或页眉中添加徽标(jpg 或 png 格式的图片)。

有没有办法做到这一点?

标签: pythonpython-docx

解决方案


添加运行并在运行中添加图片:

document = Document()
section = document.sections[0]
header = section.header
paragraph = header.paragraphs[0]
run = paragraph.add_run()
run.add_picture("my-image.png")

有关使用页眉和页脚的更多文档在这里:
https ://python-docx.readthedocs.io/en/latest/user/hdrftr.html


推荐阅读