--- comments: true --- # Document to Markdown Tutorial ## 1. Introduction Document to Markdown (doc2md) is a lightweight Office document conversion feature built into PaddleOCR. It **requires no OCR inference** — it directly parses document structure and outputs well-formed Markdown text. It is well-suited for scenarios where Word, Excel, or PowerPoint files need to be quickly converted to readable text, such as knowledge base construction, document retrieval, and content extraction. **Supported formats**: `.docx` (Word) / `.xlsx` (Excel) / `.pptx` (PowerPoint) **Feature overview:**
| Feature | Word (.docx) | Excel (.xlsx) | PowerPoint (.pptx) |
|---|---|---|---|
| Heading levels | ✅ Built-in styles + font-size heuristic + Chinese numbering | — | — |
| Text formatting (bold / italic / underline / strikethrough) | ✅ | ✅ | ✅ |
| Superscript / subscript | ✅ | ✅ | ✅ |
| Hyperlinks | ✅ | ✅ | ✅ |
| Lists (ordered / unordered / nested) | ✅ | — | — |
| Tables (with merged cells) | ✅ HTML table | ✅ HTML table | ✅ HTML table |
| Images | ✅ Proportional width | ✅ Floating images | ✅ Proportional width |
| Math formulas (OMML → LaTeX) | ✅ Inline / display formulas | ✅ Drawing-layer formulas | ✅ |
| Code blocks | ✅ Monospace font auto-detection | — | — |
| Text boxes | ✅ | — | — |
| Charts | ✅ → HTML table | — | ✅ 14 chart types |
| Headers / footers | ✅ Multi-section + odd/even pages | — | — |
| Multiple sheets / slides | — | ✅ | ✅ Separated by --- |
| Speaker notes | — | — | ✅ |
| Package | Version constraint | Purpose |
|---|---|---|
python-docx |
>=0.8.11 |
Word (.docx) document parsing |
python-pptx |
>=0.6.21 |
PowerPoint (.pptx) document parsing |
openpyxl |
>=3.0.0 |
Excel (.xlsx) document parsing |
pylatexenc |
>=2.10,<3 |
Math formula Unicode → LaTeX symbol mapping |
| Parameter | Description | Type | Default |
|---|---|---|---|
-i, --input |
Meaning: Input file path. Required (may be omitted when --formats is used).Note: Supports .docx, .xlsx, and .pptx formats. |
str |
required |
-o, --output |
Meaning: Output Markdown file path. Note: If not set, the result is printed to stdout. When set, Markdown is written to the specified file and images are saved to an images/ subdirectory alongside it. |
str |
None |
-q, --quiet |
Meaning: Quiet mode. Note: When enabled, timing and save-path messages are suppressed. |
flag | False |
--formats |
Meaning: Print the list of supported file formats and exit. Note: --input is not required when this flag is used. |
flag | False |
--no-drawings |
Meaning: Skip text box and drawing-layer content extraction. Note: Applies to .docx and .xlsx. When enabled, text boxes (docx) and drawing-layer math formulas (xlsx) are not extracted. |
flag | False |
--no-headers-footers |
Meaning: Skip header and footer extraction. Note: Applies to .docx only. |
flag | False |
--sheet-name |
Meaning: Convert only the sheet with the given name. Note: Applies to .xlsx only. All sheets are converted when not set. |
str |
None |
--max-rows |
Meaning: Maximum number of rows to convert per sheet. Note: Applies to .xlsx only. Use this to limit output for large spreadsheets. |
int |
None |
| Field | Type | Description |
|---|---|---|
markdown |
str |
The converted Markdown text |
images |
dict[str, bytes] |
Extracted images dict; key is a relative path (e.g. images/image1.png), value is raw bytes |
title |
Optional[str] |
Document title; may be None |
metadata |
dict |
Document metadata such as format type and sheet count |
| Parameter | Type | Default | Formats | Description |
|---|---|---|---|---|
extract_drawings |
bool |
True |
docx, xlsx | Whether to extract text boxes (docx) / drawing-layer math formulas (xlsx) |
extract_headers_footers |
bool |
True |
docx | Whether to extract headers and footers |
sheet_name |
Optional[str] |
None |
xlsx | Convert only the named sheet; None converts all sheets |
max_rows |
Optional[int] |
None |
xlsx | Maximum number of rows to convert per sheet |