DOCX Skill
When to use
- - Read or review DOCX content where layout matters (tables, diagrams, pagination).
- Create or edit DOCX files with professional formatting.
- Validate visual layout before delivery.
Workflow
- 1. Prefer visual review (layout, tables, diagrams).
- If
soffice and
pdftoppm are available, convert DOCX -> PDF -> PNGs.
- Or use
scripts/render_docx.py (requires
pdf2image and Poppler).
- If these tools are missing, install them or ask the user to review rendered pages locally.
- 2. Use
python-docx for edits and structured creation (headings, styles, tables, lists). - After each meaningful change, re-render and inspect the pages.
- If visual review is not possible, extract text with
python-docx as a fallback and call out layout risk. - Keep intermediate outputs organized and clean up after final approval.
Temp and output conventions
- - Use
tmp/docs/ for intermediate files; delete when done. - Write final artifacts under
output/doc/ when working in this repo. - Keep filenames stable and descriptive.
Dependencies (install if missing)
Prefer
uv for dependency management.
Python packages:
uv pip install python-docx pdf2image
If
uv is unavailable:
python3 -m pip install python-docx pdf2image
System tools (for rendering):
CODEBLOCK2
If installation isn't possible in this environment, tell the user which dependency is missing and how to install it locally.
Environment
No required environment variables.
Rendering commands
DOCX -> PDF:
CODEBLOCK3
PDF -> PNGs:
CODEBLOCK4
Bundled helper:
CODEBLOCK5
Quality expectations
- - Deliver a client-ready document: consistent typography, spacing, margins, and clear hierarchy.
- Avoid formatting defects: clipped/overlapping text, broken tables, unreadable characters, or default-template styling.
- Charts, tables, and visuals must be legible in rendered pages with correct alignment.
- Use ASCII hyphens only. Avoid U+2011 (non-breaking hyphen) and other Unicode dashes.
- Citations and references must be human-readable; never leave tool tokens or placeholder strings.
Final checks
- - Re-render and inspect every page at 100% zoom before final delivery.
- Fix any spacing, alignment, or pagination issues and repeat the render loop.
- Confirm there are no leftovers (temp files, duplicate renders) unless the user asks to keep them.
DOCX 技能
使用时机
- - 阅读或审阅对布局有要求的DOCX内容(表格、图表、分页)。
- 创建或编辑具有专业格式的DOCX文件。
- 在交付前验证视觉布局。
工作流程
- 1. 优先进行视觉审阅(布局、表格、图表)。
- 如果soffice和pdftoppm可用,将DOCX转换为PDF,再转换为PNG图片。
- 或使用scripts/render_docx.py(需要pdf2image和Poppler)。
- 如果缺少这些工具,请安装它们,或要求用户在本地审阅渲染后的页面。
- 2. 使用python-docx进行编辑和结构化创建(标题、样式、表格、列表)。
- 每次有意义的更改后,重新渲染并检查页面。
- 如果无法进行视觉审阅,使用python-docx提取文本作为备选方案,并指出布局风险。
- 保持中间输出文件有序,并在最终确认后清理。
临时文件和输出规范
- - 使用tmp/docs/存放中间文件;完成后删除。
- 在此仓库中工作时,将最终产物写入output/doc/目录。
- 保持文件名稳定且具有描述性。
依赖项(如缺失请安装)
推荐使用uv进行依赖管理。
Python包:
uv pip install python-docx pdf2image
如果uv不可用:
python3 -m pip install python-docx pdf2image
系统工具(用于渲染):
macOS(Homebrew)
brew install libreoffice poppler
Ubuntu/Debian
sudo apt-get install -y libreoffice poppler-utils
如果在此环境中无法安装,请告知用户缺少哪个依赖项以及如何在本地安装。
环境
无需设置环境变量。
渲染命令
DOCX转PDF:
soffice -env:UserInstallation=file:///tmp/loprofile$$ --headless --convert-to pdf --outdir $OUTDIR $INPUT_DOCX
PDF转PNG图片:
pdftoppm -png $OUTDIR/$BASENAME.pdf $OUTDIR/$BASENAME
集成辅助脚本:
python3 scripts/renderdocx.py /path/to/file.docx --outputdir /tmp/docx_pages
质量标准
- - 交付可直接使用的文档:一致的排版、间距、页边距和清晰的层级结构。
- 避免格式缺陷:文字被裁剪/重叠、表格损坏、字符无法阅读或使用默认模板样式。
- 图表、表格和视觉元素在渲染页面中必须清晰可辨,对齐正确。
- 仅使用ASCII连字符。避免使用U+2011(不间断连字符)和其他Unicode破折号。
- 引文和参考文献必须可读;不得保留工具标记或占位符字符串。
最终检查
- - 在最终交付前,以100%缩放比例重新渲染并检查每一页。
- 修复任何间距、对齐或分页问题,并重复渲染循环。
- 确认没有遗留文件(临时文件、重复渲染文件),除非用户要求保留。