Word to PDF Converter
Convert Word documents (.doc / .docx) to PDF with automatic format detection.
When to Use
- User mentions: "word2pdf", "Word转PDF", "Word to PDF", "doc转PDF", "docx转PDF"
- Need to convert a Word document to PDF for sharing or submission
- Need to check whether a file is .doc or .docx before converting
How It Works
- Format Detection — reads first 8 bytes to identify:
D0 CF 11 E0 ...→.doc(OLE2 Compound Binary Format)50 4B 03 04→.docx(ZIP / Office Open XML)
- Conversion — tries in order:
- Microsoft Word COM automation (
win32com) — best fidelity for both formats - LibreOffice headless (
soffice --headless) — fallback for both formats
- Microsoft Word COM automation (
Usage
python "<LOCAL_USER>/.claude/skills/word2pdf/word2pdf.py" <input.doc|input.docx> [output.pdf]
Arguments
| Argument | Required | Description |
|---|---|---|
input |
Yes | Input Word file path (.doc or .docx) |
output |
No | Output PDF path (default: same name with .pdf extension) |
Examples
# Convert .docx (auto-detect format, output = input_name.pdf)
python "<LOCAL_USER>/.claude/skills/word2pdf/word2pdf.py" "report.docx"
# Convert .doc (legacy binary format)
python "<LOCAL_USER>/.claude/skills/word2pdf/word2pdf.py" "old_document.doc"
# Convert with custom output path
python "<LOCAL_USER>/.claude/skills/word2pdf/word2pdf.py" "report.docx" "output.pdf"
Dependencies
- Primary: Microsoft Word (installed) +
pywin32python -m pip install pywin32 - Fallback: LibreOffice (any recent version)
Workflow
- Validate input file exists
- Detect format via magic bytes (report
.docor.docx) - Try Microsoft Word COM conversion
- If unavailable, try LibreOffice headless
- Report output path, file size, and page count
Rules
- Always use
PYTHONIOENCODING=utf-8on Windows - Report detected format to user before converting
- Report any conversion warnings or errors
- If neither Word nor LibreOffice is available, inform the user to install one