petr
petr

Reputation: 11

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?

Upvotes: 1

Views: 2801

Answers (1)

scanny
scanny

Reputation: 28883

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

Upvotes: 4

Related Questions