MD to PDF

Mermaid diagrams,
printed properly

Paste Markdown containing Mermaid and get a PDF where the diagrams are real vector graphics — sharp at any zoom, with selectable text and labels that actually fit inside their boxes.

document.md
Source
77 lines · 308 wordsLn 1, Col 1

Why Mermaid diagrams come out wrong almost everywhere else

Mermaid decides how big every box should be by measuring the width of the text that goes inside it. That measurement is the whole problem. If it happens before the web font has finished loading, the boxes are sized against a fallback font with different metrics, and the real text is then drawn into a box that was measured for something narrower. The label is clipped mid-word, and because the layout is already committed nothing later can rescue it.

  • Labels cut off part-way through a word — the classic symptom, and the reason exports from comparable tools show boxes reading "Normalized subscriptic" or "Apple App Sto"
  • Diagrams exported as raster images, which look acceptable on screen and print soft and blurry
  • Diagrams dropped entirely, leaving a silent gap where the chart should be, with no error to tell you
  • Arrows that land in the wrong place because the node they point at was measured at the wrong size

How this converter avoids it

The typefaces are loaded and confirmed ready before a single diagram is drawn, so every measurement is taken against the font that will actually be used. The diagram is then rendered as SVG and embedded as vector art rather than a screenshot. Two things follow from that: it stays sharp at any zoom or print resolution, and the label text remains real text — selectable, searchable, and readable by a screen reader.

Flowcharts

The most common kind, and the one most likely to expose the label-measurement bug because node labels vary so much in length. Node shapes, edge labels, and subgraphs all export intact.

```mermaid
flowchart TD
    A[Upload Markdown] --> B{Contains diagrams?}
    B -- Yes --> C[Load fonts first]
    B -- No --> D[Render text only]
    C --> E[Draw Mermaid as SVG]
    E --> F[Embed as vector art]
    D --> F
    F --> G[(Download PDF)]
```
A flowchart with mixed label lengths, subgraphs and edge labels.

Sequence diagrams

Participant boxes, activation bars, loops and notes all survive. Long participant names are the usual failure case elsewhere, because the lifeline spacing is calculated from the measured name width.

```mermaid
sequenceDiagram
    participant B as Browser (your machine)
    participant S as Render service
    participant C as Headless Chrome
    B->>S: POST /api/render with Markdown
    S->>C: Load print stage
    activate C
    loop For each diagram
        C->>C: Measure labels, draw SVG
    end
    C-->>S: Tagged PDF
    deactivate C
    S-->>B: application/pdf
    Note over B,S: Nothing is written to disk
```
Participants with deliberately long names, plus a loop and a note.

Class, state and entity-relationship diagrams

The structural diagram types export the same way. Class members and their visibility markers, state transitions, and ER cardinality notation all keep their formatting.

```mermaid
erDiagram
    DOCUMENT ||--o{ HEADING : contains
    DOCUMENT ||--o{ DIAGRAM : contains
    DOCUMENT {
        string title
        int pageCount
    }
```

```mermaid
stateDiagram-v2
    [*] --> Editing
    Editing --> Rendering: Download PDF
    Rendering --> Editing: Error
    Rendering --> [*]: File returned
```
An ER diagram and a state diagram; both render as vector art.

Gantt charts and pie charts

Both are supported, and both are worth checking in the preview before exporting. A Gantt chart is usually the widest thing in a document, and a pie chart with long slice labels is the other common place clipping used to appear.

```mermaid
gantt
    title Release plan
    dateFormat YYYY-MM-DD
    section Writing
    Draft the spec      :done,    des1, 2026-01-05, 10d
    Review              :active,  des2, after des1, 5d
    section Build
    Implementation      :         des3, after des2, 20d
    Ship                :milestone, after des3, 0d
```
A Gantt chart with sections and dependencies.

Diagrams that are wider than the page

A flowchart with many parallel branches can be wider than the printable area, and this is the one case where a diagram needs help from you. It is scaled down to fit rather than being cropped, so nothing is lost, but scaled far enough the labels become uncomfortable to read. Three things fix it: switch the page to landscape in the style panel, change the flowchart direction from LR to TD so it grows downward instead of sideways, or split it into two diagrams. The preview shows the real printed width, so you can see which is needed before exporting.

Page breaks around diagrams

A diagram is never sliced in half. One that will not fit in the space remaining on a page moves whole to the next one, which is why a document with several large charts sometimes has more white space at the foot of a page than you would expect. That is deliberate: half a flowchart is worth less than a short page.

When a diagram will not parse

Mermaid is strict about syntax, and a stray character is enough to break a chart. Rather than dropping it silently or failing the whole export, the diagram's source is printed in its place, so you can see exactly what was fed in and where it went wrong. One broken diagram never costs you the rest of the document.

  • Check the first line names a diagram type — flowchart, sequenceDiagram, erDiagram and so on
  • Quote labels containing brackets, colons or hyphens, which otherwise read as syntax
  • Keep node ids free of spaces; put the spaces in the label instead, as in A[My label]
  • Indentation is not significant, but a missing arrow head such as -> where --> is meant will stop the parse

Common questions

Can I convert Mermaid diagrams to PDF for free?

Yes. Paste the Markdown containing your Mermaid blocks, or drop the .md file in, and download the PDF. No account, no watermark, no page limit and no payment.

Are the diagrams images or vector graphics in the PDF?

Vector graphics. They stay sharp at any zoom and print at full resolution, and the label text remains selectable and searchable rather than being flattened into a picture.

Which Mermaid diagram types are supported?

Flowcharts, sequence, class, state, entity-relationship, Gantt, pie, user journey and Git graphs. If Mermaid can draw it, it is embedded in the PDF the same way.

Why do my diagram labels get cut off in other tools?

Because the boxes were measured before the font finished loading, so the real text is drawn into a box sized for different metrics. Here fonts are loaded before any diagram is drawn, so the box and its label always agree.

What happens if my Mermaid syntax is wrong?

The diagram's source is printed in its place so you can see what went wrong. The rest of the document still converts, and you never get a silent blank gap.

My flowchart is too wide for the page. What can I do?

Switch to landscape in the style panel, change the direction from LR to TD so it grows downward, or split it into two diagrams. It is scaled to fit rather than cropped, so nothing is lost either way.