From 717f2c40c56b0289b288281804f3d3f5eb87b4c2 Mon Sep 17 00:00:00 2001 From: Vasanth Date: Wed, 28 Oct 2026 17:02:20 +0530 Subject: [PATCH] rpa-bot-handoff: fit the SOP in 4 real pages The first SOP (MEK Charge Reconciliation, 1,327 words) printed on 5 pages: Word's 2.5 cm default margins and 10.5 pt table text. to_docx.py now uses 1.8/1.6 cm margins and 9.5 pt table text; the trimmed SOP (1,226 words) prints on 3 pages. The verify step counts real pages through Word when it is installed. Co-Authored-By: Claude Opus 5.5 --- skills/rpa-bot-handoff/SKILL.md | 1 + skills/rpa-bot-handoff/templates/to_docx.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/skills/rpa-bot-handoff/SKILL.md b/skills/rpa-bot-handoff/SKILL.md index 19edb4c..c787714 100644 --- a/skills/rpa-bot-handoff/SKILL.md +++ b/skills/rpa-bot-handoff/SKILL.md @@ -68,6 +68,7 @@ Copy `templates/HANDOVER-SOP.md` to the bot's repo root and fill every `{{PLACEH 3. No file:line, function names, env var names, client names, PHI, credentials or IPs. 4. Run `python /templates/to_docx.py HANDOVER-SOP.md -o " Handover SOP.docx"`. If it reports more than 1,400 words, cut: merge rows, drop explanations, never drop a message. 5. Open the docx with python-docx: 5 numbered section headings, no `**` or `|---` left. +6. When Word is installed, count the real pages (PowerShell: open it with `Word.Application`, read `ComputeStatistics(2)`). More than 4: cut words, then rebuild. ## 5. Hand over diff --git a/skills/rpa-bot-handoff/templates/to_docx.py b/skills/rpa-bot-handoff/templates/to_docx.py index cae2835..30d7993 100644 --- a/skills/rpa-bot-handoff/templates/to_docx.py +++ b/skills/rpa-bot-handoff/templates/to_docx.py @@ -16,9 +16,9 @@ import tempfile from pathlib import Path from docx import Document -from docx.shared import Pt +from docx.shared import Cm, Pt -MAX_WORDS = 1400 # about 4 pages with tables +MAX_WORDS = 1400 # about 4 pages with the margins and table font below INLINE = re.compile(r"(\*\*[^*]+\*\*|\*[^*\s][^*]*\*|`[^`]+`)") @@ -42,6 +42,9 @@ def convert(md_text, out_path): doc = Document() doc.styles["Normal"].font.name = "Calibri" doc.styles["Normal"].font.size = Pt(10.5) + for section in doc.sections: # Word's 2.5 cm default margins push a 4-page SOP onto 5 + section.left_margin = section.right_margin = Cm(1.8) + section.top_margin = section.bottom_margin = Cm(1.6) lines = md_text.splitlines() i = 0 while i < len(lines): @@ -69,6 +72,8 @@ def convert(md_text, out_path): for c, text in enumerate(row): par = table.cell(r, c).paragraphs[0] add_runs(par, text) + for run in par.runs: + run.font.size = Pt(9.5) if r == 0: for run in par.runs: run.bold = True