Fix first-page line numbering off-by-one in transcript DOCX
- Remove docGrid element to prevent phantom grid-based line offset. - Ensure exactly one lnNumType element (no duplicates). - First visible line on page 1 now correctly numbered as 1.
This commit is contained in:
@@ -318,7 +318,7 @@ def _create_transcript_section_properties(section):
|
||||
- Margins: 1 inch all sides
|
||||
- Single column layout
|
||||
- Line numbering: start=1, countBy=1, restart each page
|
||||
- Disable document grid to avoid off-by-one line numbering
|
||||
- Remove document grid to avoid off-by-one line numbering
|
||||
"""
|
||||
sectPr = section._sectPr
|
||||
|
||||
@@ -341,10 +341,13 @@ def _create_transcript_section_properties(section):
|
||||
_set_element_attr(cols, "num", "1")
|
||||
_set_element_attr(cols, "space", "720")
|
||||
|
||||
# Disable document grid to avoid Word counting phantom grid lines
|
||||
docGrid = sectPr.find(f"{{{W_NS}}}docGrid")
|
||||
if docGrid is not None:
|
||||
_set_element_attr(docGrid, "type", "none")
|
||||
# Remove document grid entirely to avoid phantom grid-based line numbering
|
||||
for docGrid in sectPr.findall(f"{{{W_NS}}}docGrid"):
|
||||
sectPr.remove(docGrid)
|
||||
|
||||
# Ensure exactly one lnNumType element (remove any existing)
|
||||
for lnNumType in sectPr.findall(f"{{{W_NS}}}lnNumType"):
|
||||
sectPr.remove(lnNumType)
|
||||
|
||||
# Line numbering: start=1, countBy=1, restart each page
|
||||
lnNumType = OxmlElement("w:lnNumType")
|
||||
|
||||
Reference in New Issue
Block a user