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
|
||||
|
||||
# Lines per page before restarting numbering
|
||||
lines_per_page = 32
|
||||
lines_per_page = 29
|
||||
|
||||
# Current line counter for visual lines
|
||||
line_number = 0
|
||||
@@ -472,21 +472,21 @@ def create_transcript_docx(text: str, filename: str):
|
||||
def ensure_new_page_if_needed():
|
||||
nonlocal line_number
|
||||
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()
|
||||
# Page break via rPr: no line number, no text
|
||||
pPr = p_break._p.get_or_add_pPr()
|
||||
# Clear any existing line-related props
|
||||
|
||||
# Clear any inherited formatting
|
||||
for child in list(pPr):
|
||||
tag = child.tag.split("}")[-1] if "}" in child.tag else child.tag
|
||||
if tag in ("tabs", "spacing", "ind"):
|
||||
pPr.remove(child)
|
||||
# Add a page break run
|
||||
r = p_break.add_run()
|
||||
rPr = r._r.get_or_add_rPr()
|
||||
br = OxmlElement("w:br")
|
||||
br.set("{http://schemas.openxmlformats.org/wordprocessingml/2006/main}type", "page")
|
||||
rPr.append(br)
|
||||
|
||||
# Standard page break via paragraph property
|
||||
page_break = OxmlElement("w:pageBreak")
|
||||
page_break.set("{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val", "1")
|
||||
pPr.append(page_break)
|
||||
|
||||
# Reset line counter for new page
|
||||
line_number = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user