简体   繁体   中英

How to add a picture to a header/footer in python-docx

I would like to add a logo (picture in jpg or png) to a footer or header by using python-docx.

Is there a way how to do it?

Add a run and add a picture to the run:

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

More documentation on working with headers and footers is here:
https://python-docx.readthedocs.io/en/latest/user/hdrftr.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM