SciFig
Tutorials··5 min read

Mermaid to Image: Export Diagrams (2026)

How to export Mermaid diagrams to SVG, PNG, and PDF from the CLI, VS Code, and CI, plus what to do when the output is not publication quality.

SciFig Team
SciFig Team
Scientific Illustration Experts

Export Mermaid diagrams to SVG or PDF with the mermaid-cli tool.

Mermaid renders diagrams from text, which makes it excellent for documentation that lives in version control. Getting a file out of it — one you can drop into a manuscript, a slide, or a poster — is a separate step that trips people up, mostly because the default export is a PNG at screen resolution.

A Mermaid flowchart shown as source text beside its rendered SVG output (Figure generated with SciFig)
A Mermaid flowchart shown as source text beside its rendered SVG output (Figure generated with SciFig)

The Command Line Route

The official tool is @mermaid-js/mermaid-cli, which exposes an mmdc command:
npm install -g @mermaid-js/mermaid-cli
 
mmdc -i diagram.mmd -o diagram.svg          # vector, preferred
mmdc -i diagram.mmd -o diagram.pdf          # vector PDF
mmdc -i diagram.mmd -o diagram.png -s 3     # raster at 3x scale
Always prefer SVG or PDF. Both are vector, so text stays sharp at any size. Use PNG only when a destination cannot accept vector, and then set an explicit scale factor — the default resolution is too low for print.
FormatVectorGood forAvoid when
SVGYesWeb, further editing, most journalsTarget requires EPS
PDFYesManuscripts, print, slidesYou need to edit in a browser tool
PNGNoChat, wikis, quick previewsPrint or any scaling

See AI Scientific Figure Generation in Action

Watch how researchers create publication-ready scientific figures from text descriptions.

Explore the Tool

Other Export Routes

VS Code. The Markdown Preview Mermaid Support extension renders diagrams inline, and the Mermaid Editor extension adds direct SVG and PNG export. Convenient while drafting.
Mermaid Live Editor. The browser editor exports SVG and PNG directly and is the fastest option for a one-off diagram, though it means pasting your diagram into a hosted service — a consideration if the content is sensitive.
CI pipelines. Because mmdc is a CLI, diagram rendering can be a build step. A common pattern is committing .mmd sources and generating images during documentation builds, so the rendered output never goes stale relative to the source.
- run: npm install -g @mermaid-js/mermaid-cli
- run: mmdc -i docs/architecture.mmd -o docs/architecture.svg
A CI pipeline diagram showing Mermaid source committed to the repository and images generated during the documentation build (Figure generated with SciFig)
A CI pipeline diagram showing Mermaid source committed to the repository and images generated during the documentation build (Figure generated with SciFig)
The same Mermaid flowchart rendered in the default and neutral themes, showing the difference in print legibility (Figure generated with SciFig)
The same Mermaid flowchart rendered in the default and neutral themes, showing the difference in print legibility (Figure generated with SciFig)

Controlling Appearance

Mermaid's defaults are built for documentation, not for publication. Three levers matter:

  • Themes. %%{init: {'theme':'neutral'}}%% at the top of the file. neutral and base print better than the default.
  • Fonts. Set fontFamily in the init block so the diagram matches the surrounding document.
  • Direction. graph LR versus graph TD changes the aspect ratio, which matters more than it sounds when fitting a diagram into a column.
%%{init: {'theme':'neutral', 'themeVariables': {'fontFamily':'Helvetica'}}}%%
graph LR
  A[Sample collection] --> B[Extraction]
  B --> C[Sequencing]
  C --> D[Analysis]

When Mermaid Is the Wrong Tool

Mermaid computes layout automatically, and you get limited control over it. That is a feature for documentation and a limitation for scientific figures where composition carries meaning.

Reach for something else when you need precise spatial arrangement, when the diagram must match a journal's visual conventions, or when elements need to be positioned to reflect real relationships such as anatomical position or temporal sequence. A workable compromise: generate the structure in Mermaid, export SVG, then finish in a vector editor — accepting that the finishing step breaks regeneration.

A Mermaid auto-layout diagram beside the same content rearranged manually for a manuscript figure (Figure generated with SciFig)
A Mermaid auto-layout diagram beside the same content rearranged manually for a manuscript figure (Figure generated with SciFig)

Tip

Commit the .mmd source alongside the exported image. The source diffs meaningfully in review and regenerates when things change; the image is what people actually look at. Keeping only one of the two costs you either reviewability or convenience.

Create Scientific Figures Now

Describe your scientific figure in natural language — get publication-ready illustrations in minutes.

Try Free
When a diagram needs composition Mermaid cannot give, text to diagram generator produces an editable diagram from plain language, and text to figure handles publication figures. See our guide to visualizing research for the broader workflow.

Related reading: Visualize Research with AI Text-to-Figure, 10 Best Scientific Illustration Tools in 2026.

FAQ

Recommended next

Related scientific figure resources

Go deeper with the most relevant SciFig pages for this article.

Call to action background

Ready to start?

Publication-ready scientific figures, in minutes

Start Creating Free

Free to start · No credit card required · Built for researchers