如何在python-docx中为页眉页脚添加图片?

问题描述 投票:0回答:1

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

有什么方法可以做到这一点吗?

python python-docx
1个回答
0
投票

添加一个运行,并在运行中添加一个图片。

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.ioenlatestuserhdrftr.html。

© www.soinside.com 2019 - 2024. All rights reserved.