Page numbering on Footer in Python docx

Hello Dear Forummers !

İ am trying to add Page Number into Python-docx Document’s Footer to be Automatically increased from one page to another

I have searched some methods in StackOverFlow but they don’t working*
StackOverFlow Tittle

Do you have any ideas how to do it ?

Thank you very much in advance !

I tried reading the docs for python-docx (I have never used it).

Opening the XML inside a m$ft word docx with the automatic page headers added looked like it was very complicated in its implementation.

Then reading the stack-overflow posts you linked to leads me to think that the best idea on that SO thread was to create a template .docx file in word that contains the auto-incrementing footers and then load that file and edit it using python-docx, adding whatever information you want instead of starting from scratch.

ms word - Add page number using python-docx - Stack Overflowimage

1 Like

Thank you Ian for your answer,

But I cannot create Template before as I don’t know how many pages will require user’s document.
And where I can put the Template file in Anvil so that it could be read by Python-docx?

Like I said I have never used python-docx but have you tried making a .docx in word with auto-incrementing page number footers and then using python-docx to just add more pages? The docs said something about adding page breaks? I’m not sure how it works.

When I made one it created a footer1.xml file inside the .docx with a whole bunch of macros and formatting applied that seem to all work together in some Microsoft style overly complicated way to make the page number auto-increment.

Heres what the XML looks like (jibber jabber):

1 Like