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.
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.