Set 29 lines per page and fix page break insertion
- Use 29 visual lines per page before inserting a page break. - Use w:pageBreak element for reliable page breaks across editors. - Restart line numbering at 1 on each new page.
This commit is contained in:
+10
-10
@@ -461,7 +461,7 @@ def create_transcript_docx(text: str, filename: str):
|
|||||||
max_chars = 58
|
max_chars = 58
|
||||||
|
|
||||||
# Lines per page before restarting numbering
|
# Lines per page before restarting numbering
|
||||||
lines_per_page = 32
|
lines_per_page = 29
|
||||||
|
|
||||||
# Current line counter for visual lines
|
# Current line counter for visual lines
|
||||||
line_number = 0
|
line_number = 0
|
||||||
@@ -472,21 +472,21 @@ def create_transcript_docx(text: str, filename: str):
|
|||||||
def ensure_new_page_if_needed():
|
def ensure_new_page_if_needed():
|
||||||
nonlocal line_number
|
nonlocal line_number
|
||||||
if line_number >= lines_per_page:
|
if line_number >= lines_per_page:
|
||||||
# Insert a page break paragraph
|
# Insert a page break paragraph (no line number, no text)
|
||||||
p_break = doc.add_paragraph()
|
p_break = doc.add_paragraph()
|
||||||
# Page break via rPr: no line number, no text
|
|
||||||
pPr = p_break._p.get_or_add_pPr()
|
pPr = p_break._p.get_or_add_pPr()
|
||||||
# Clear any existing line-related props
|
|
||||||
|
# Clear any inherited formatting
|
||||||
for child in list(pPr):
|
for child in list(pPr):
|
||||||
tag = child.tag.split("}")[-1] if "}" in child.tag else child.tag
|
tag = child.tag.split("}")[-1] if "}" in child.tag else child.tag
|
||||||
if tag in ("tabs", "spacing", "ind"):
|
if tag in ("tabs", "spacing", "ind"):
|
||||||
pPr.remove(child)
|
pPr.remove(child)
|
||||||
# Add a page break run
|
|
||||||
r = p_break.add_run()
|
# Standard page break via paragraph property
|
||||||
rPr = r._r.get_or_add_rPr()
|
page_break = OxmlElement("w:pageBreak")
|
||||||
br = OxmlElement("w:br")
|
page_break.set("{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val", "1")
|
||||||
br.set("{http://schemas.openxmlformats.org/wordprocessingml/2006/main}type", "page")
|
pPr.append(page_break)
|
||||||
rPr.append(br)
|
|
||||||
# Reset line counter for new page
|
# Reset line counter for new page
|
||||||
line_number = 0
|
line_number = 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user