# Markdown to Word API

> Convert Markdown or HTML to an editable Word .docx with real styles, lists, tables, code, images, page size, margins, page numbers and a Decree 30 preset.

- Endpoint: `POST https://apibox.io.vn/v1/md-docx`
- Category: Files
- HTML docs: https://apibox.io.vn/docs/md-docx/ (Vietnamese: https://apibox.io.vn/vi/docs/md-docx/)
- Online tool: https://apibox.io.vn/tools/md-docx/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Send `markdown` (GitHub-flavoured: headings, bold / italic / strikethrough, inline code, links, nested bullet and numbered lists, task lists, tables with alignment, block quotes, code blocks, horizontal rules, images) or `html` and get a .docx built with real Word styles (Heading 1-6, List Paragraph, Quote, Source Code), so the navigation pane, table of contents and style changes work as in a hand-made document. Numbered lists keep their start number; table header rows repeat on each page.

Presets: `default` (Calibri 11, 2.54 cm margins), `report` (Arial, justified) and `nd30` for Vietnamese administrative documents under Decree 30/2020/NĐ-CP: A4, Times New Roman 14 pt (13 with font_size=13), margins top / bottom 20 mm, left 30 mm, right 15 mm, justified text, first line indented 1.27 cm, 6 pt between paragraphs, page numbers centred in the top margin and hidden on the first page. Override any of `font`, `font_size`, `line_spacing`, `margins` (mm, "top,right,bottom,left"), `page` (a4, a5, a3, letter, legal), `orientation`, `page_numbers`, `header_text`, `footer_text`, `first_line_indent`; `toc=true` adds a table of contents field that Word fills when the file is opened.

Images can be data URLs or public http(s) URLs (PNG, JPEG, GIF; up to 20 fetched, 5 MB each) and are scaled to the text width. The output is a .docx file, or JSON with base64 (`format=json`). Files are generated in memory and not stored.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `markdown` | body | string | yes |  | Markdown text (or a text/plain body). Or send `html`. |
| `html` | body | string | no |  | HTML instead of Markdown (converted first). |
| `preset` | body | string | no | `default` | `default`, `report` or `nd30` (Decree 30/2020). |
| `font` | body | string | no |  | Font name, e.g. `Times New Roman`. |
| `font_size` | body | number | no |  | Body size in points (6-48). |
| `line_spacing` | body | number | no |  | Line spacing in lines (0.8-3). |
| `margins` | body | string | no |  | Millimetres: `top,right,bottom,left`, one value, or an object. |
| `page` | body | string | no | `a4` | `a4`, `a5`, `a3`, `letter` or `legal`. |
| `orientation` | body | string | no | `portrait` | `portrait` or `landscape`. |
| `page_numbers` | body | string | no |  | `none`, `footer` or `header` (preset default). |
| `toc` | body | boolean | no | `false` | Insert a table of contents field. |
| `header_text` | body | string | no |  | Text in the page header. |
| `footer_text` | body | string | no |  | Text in the page footer. |
| `format` | body | string | no | `docx` | `docx` (file) or `json` (base64 + summary). |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/md-docx" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"markdown":"# Báo cáo tuần\n\nNội dung **chính**.\n\n- Việc 1\n- Việc 2\n\n| Hạng mục | Tiến độ |\n|---|---:|\n| API | 90% |","preset":"nd30","format":"json"}'
```

## Example response

```json
{
  "filename": "Báo cáo tuần.docx",
  "preset": "nd30",
  "page": {
    "size": "a4",
    "orientation": "portrait",
    "margins_mm": {
      "top": 20,
      "right": 15,
      "bottom": 20,
      "left": 30
    }
  },
  "font": "Times New Roman",
  "font_size": 14,
  "paragraphs": 6,
  "images": 0,
  "links": 0,
  "warnings": [],
  "docx_base64": "UEsDBBQAAAgIAAAAAADpEG/9ZAEAALkFAAATAAAAW0NvbnRlbnRfVHlwZXNd…",
  "bytes": 5587
}
```

## Use cases

- Turn AI-generated Markdown reports into Word files for clients
- Produce Decree 30 formatted drafts for Vietnamese agencies and schools
- Export Notion / Obsidian notes or CMS HTML to .docx
- Generate weekly reports with tables and charts as images

## FAQ

### Does it follow Decree 30/2020 completely?

preset=nd30 applies the page, font, spacing, indentation and page-number rules of Annex I. The national motto block, document number and signature layout are content you write; check the final document against the decree.

### Can I convert Word back to Markdown?

Yes, with /v1/docx-convert.

### Why is the table of contents empty at first?

A TOC is a Word field: Word asks to update fields when the file opens (or press F9). Other editors may show the placeholder text.
