Fix page numbering: correct field insertion for PAGE and NUMPAGES
This commit is contained in:
+25
-25
@@ -345,44 +345,44 @@ def _setup_docx_style(doc, enable_line_numbering=False):
|
|||||||
|
|
||||||
# PAGE field (current page number)
|
# PAGE field (current page number)
|
||||||
run_page = p.add_run()
|
run_page = p.add_run()
|
||||||
r_page = run_page._r
|
r = run_page._r
|
||||||
r_page.clear() # remove default empty run content
|
r.clear()
|
||||||
|
|
||||||
fldCharBegin = OxmlElement("w:fldChar")
|
fldChar_begin = OxmlElement("w:fldChar")
|
||||||
fldCharBegin.set(qn("w:fldCharType"), "begin")
|
fldChar_begin.set(qn("w:fldCharType"), "begin")
|
||||||
r_page.append(fldCharBegin)
|
r.append(fldChar_begin)
|
||||||
|
|
||||||
instrTextPage = OxmlElement("w:instrText")
|
instrText = OxmlElement("w:instrText")
|
||||||
instrTextPage.set(qn("xml:space"), "preserve")
|
instrText.set(qn("xml:space"), "preserve")
|
||||||
instrTextPage.text = "PAGE"
|
instrText.text = "PAGE"
|
||||||
r_page.append(instrTextPage)
|
r.append(instrText)
|
||||||
|
|
||||||
fldCharEnd = OxmlElement("w:fldChar")
|
fldChar_end = OxmlElement("w:fldChar")
|
||||||
fldCharEnd.set(qn("w:fldCharType"), "end")
|
fldChar_end.set(qn("w:fldCharType"), "end")
|
||||||
r_page.append(fldCharEnd)
|
r.append(fldChar_end)
|
||||||
|
|
||||||
# Static text: " of "
|
# " of " text
|
||||||
run_of = p.add_run(" of ")
|
run_of = p.add_run(" of ")
|
||||||
run_of.font.name = "Courier"
|
run_of.font.name = "Courier"
|
||||||
run_of.font.size = Pt(10)
|
run_of.font.size = Pt(10)
|
||||||
|
|
||||||
# NUMPAGES field (total pages)
|
# NUMPAGES field (total pages)
|
||||||
run_numpages = p.add_run()
|
run_numpages = p.add_run()
|
||||||
r_numpages = run_numpages._r
|
r = run_numpages._r
|
||||||
r_numpages.clear()
|
r.clear()
|
||||||
|
|
||||||
fldCharBegin2 = OxmlElement("w:fldChar")
|
fldChar_begin = OxmlElement("w:fldChar")
|
||||||
fldCharBegin2.set(qn("w:fldCharType"), "begin")
|
fldChar_begin.set(qn("w:fldCharType"), "begin")
|
||||||
r_numpages.append(fldCharBegin2)
|
r.append(fldChar_begin)
|
||||||
|
|
||||||
instrTextNumpages = OxmlElement("w:instrText")
|
instrText = OxmlElement("w:instrText")
|
||||||
instrTextNumpages.set(qn("xml:space"), "preserve")
|
instrText.set(qn("xml:space"), "preserve")
|
||||||
instrTextNumpages.text = "NUMPAGES"
|
instrText.text = "NUMPAGES"
|
||||||
r_numpages.append(instrTextNumpages)
|
r.append(instrText)
|
||||||
|
|
||||||
fldCharEnd2 = OxmlElement("w:fldChar")
|
fldChar_end = OxmlElement("w:fldChar")
|
||||||
fldCharEnd2.set(qn("w:fldCharType"), "end")
|
fldChar_end.set(qn("w:fldCharType"), "end")
|
||||||
r_numpages.append(fldCharEnd2)
|
r.append(fldChar_end)
|
||||||
|
|
||||||
|
|
||||||
def _add_cover_page(doc, doc_type, date, description):
|
def _add_cover_page(doc, doc_type, date, description):
|
||||||
|
|||||||
Reference in New Issue
Block a user