Working with Headers/Footers
Working with Headers/Footers
from docx import Document
doc = Document()
# Add header
section = doc.sections[0]
header = section.header
header_para = header.paragraphs[0]
header_para.text = "Document Header"
# Add footer
footer = section.footer
footer_para = footer.paragraphs[0]
footer_para.text = "Page Footer"
doc.save("with_header_footer.docx")