| name | docx-svg-to-pdf |
| description | Convert Word .docx documents containing embedded SVG figures into PDF while preserving vector zoom quality. Use when normal Word or WPS PDF export makes SVG diagrams blurry, when a user asks to keep SVG/vector properties after DOCX-to-PDF conversion, or when draw.io/diagrams.net-style SVGs with foreignObject text need a vector-safe PDF result. |
DOCX SVG To PDF
Overview
Use this skill when a DOCX already contains embedded Office SVG figures, but direct PDF export rasterizes them and makes zoomed diagrams unreadable. The workflow keeps Word responsible for the overall pagination, then replaces the visible rasterized figure regions with vector PDFs converted directly from the embedded SVG assets inside the DOCX package.
Workflow
- Put the final PDF under
outputs/<task_name>/versions/vNNN/.
- Put all intermediates under
scripts/work/<task_name>/<run_name>/.
- Use
scripts/convert_docx_svg_to_vector_pdf.py as the default entry point. It will:
- export a base PDF from Microsoft Word COM,
- extract the ordered
asvg:svgBlip SVG assets from the DOCX,
- convert each extracted SVG to a single-page vector PDF with PyMuPDF,
- detect the large rasterized figure regions in the base PDF,
- overlay the vector PDFs back into the report in reading order.
- Keep the default
--word-method print unless you have evidence that export behaves better for the specific document.
- If the document uses captions other than
Figure , pass a matching --caption-token. If captions are unreliable, pass an empty token and let the script scan all pages.
Command
python scripts/convert_docx_svg_to_vector_pdf.py \
'<source.docx>' \
'<target.pdf>' \
--work-dir '<scripts/work/.../run_dir>'
Note: Ensure PyMuPDF (pip install pymupdf) and python-docx are installed in your Python environment.
Validation
After conversion, verify all of the following before claiming success:
- The target PDF exists.
patch_report.json contains the same number of figure overlays as the DOCX SVG count.
vector_pdf_report.json shows each converted figure PDF is single-page and images = 0.
- At least one dense figure page, usually the class diagram page, shows a high drawing count instead of collapsing to one large JPEG.
Limits
- This workflow requires Windows and Microsoft Word COM. It is not a LibreOffice or WPS workflow.
- It preserves visible vector fidelity. Some SVG text may become path outlines inside the vector PDF, so text may not remain selectable even though zoom quality stays sharp.
- If the DOCX has no
asvg:svgBlip entries, this skill is not the right tool; use the normal DOCX-to-PDF path instead.
- If the slot count does not match the SVG count, inspect the base PDF and adjust
--caption-token, --area-threshold, or --merge-gap instead of forcing the patch.
Key Scripts
scripts/export_docx_to_pdf_word.py: raw Word COM PDF export helper for base-PDF generation and diagnostics.
scripts/convert_docx_svg_to_vector_pdf.py: default end-to-end conversion pipeline for preserving SVG vector quality in the final PDF.
Trigger Examples
- “把这个带 SVG 图的 Word 文档转成 PDF,但放大后不能糊。”
- “WPS 导出来的 PDF 把类图弄模糊了,帮我保留 SVG 矢量效果。”
- “Convert this DOCX to PDF and keep the embedded SVG diagrams crisp when zooming.”