1
---
2
name: drawio
3
description: Generate draw.io diagrams as .drawio files and export to PNG/SVG/PDF with embedded XML
4
---
5
6
# Draw.io Diagram Skill
7
8
Generate draw.io diagrams as native `.drawio` files and export them to PNG images that can be embedded in Word documents.
9
10
## How to Create a Diagram
11
12
1. **Generate draw.io XML** in `mxGraphModel` format for the requested diagram
13
2. **Write the XML** to a `.drawio` file using the create/edit file tool
14
3. **Export to PNG** using the bundled export script
15
16
## Bundled Export Script
17
18
This skill includes `drawio-to-png.mjs`, a Node.js export script with two rendering backends:
19
20
1. **draw.io CLI** (pixel-perfect, fastest) — used automatically if draw.io desktop is installed
21
2. **Official draw.io viewer in headless browser** (pixel-perfect, needs Chromium/Edge) — fallback when CLI is unavailable
22
23
### Usage
24
25
```bash
26
# Install dependencies (one-time, from the scripts folder)
27
cd skills/drawio/scripts && npm install
28
29
# Export a single diagram
30
node skills/drawio/scripts/drawio-to-png.mjs <input.drawio> [output.png]
31
32
# Export all .drawio files in a directory
33
node skills/drawio/scripts/drawio-to-png.mjs --dir <directory>
34
35
# Force a specific renderer
36
node skills/drawio/scripts/drawio-to-png.mjs --renderer=cli|viewer|auto <input.drawio>
37
```
38
39
### Skill Folder Contents
40
41
| File | Purpose |
42
|------|---------|
43
| `SKILL.md` | This instruction file |
44
| `scripts/drawio-to-png.mjs` | Node.js export script (CLI + browser fallback) |
45
| `scripts/package.json` | Dependencies (`puppeteer-core`) |
46
47
## Supported Export Formats
48
49
| Format | Embed XML | Notes |
50
|--------|-----------|-------|
51
| `png` | Yes | Viewable everywhere, editable in draw.io |
52
| `svg` | Yes | Scalable, editable in draw.io |
53
| `pdf` | Yes | Printable, editable in draw.io |
54
55
## Draw.io XML Style Conventions
56
57
Use these styles for consistent, professional diagrams:
58
59
```xml
60
<!-- Primary service (highlighted) -->
61
<mxCell style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;strokeWidth=2;arcSize=12;shadow=1;" />
62
63
<!-- External system -->
64
<mxCell style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;" />
65
66
<!-- Success/processing stage -->
67
<mxCell style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;" />
68
69
<!-- Warning/quality gate -->
70
<mxCell style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" />
71
72
<!-- Error/failure path -->
73
<mxCell style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;" />
74
75
<!-- Data store (cylinder) -->
76
<mxCell style="shape=cylinder3;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" />
77
78
<!-- Arrow -->
79
<mxCell style="edgeStyle=orthogonalEdgeStyle;rounded=1;strokeColor=#6c8ebf;strokeWidth=2;" />
80
```
81
82
## Locating the draw.io CLI
83
84
Try `drawio` first (works if on PATH), then fall back:
85
86
- **Windows**: `"C:\Program Files\draw.io\draw.io.exe"`
87
- **macOS**: `/Applications/draw.io.app/Contents/MacOS/draw.io`
88
- **Linux**: `drawio` (via snap/apt/flatpak)
89
90
### CLI Export Command
91
92
```bash
93
drawio -x -f png -e -b 10 -o <output.png> <input.drawio>
94
```
95
96
Flags: `-x` (export), `-f` (format), `-e` (embed diagram XML), `-b` (border), `-o` (output path).
97