Why Mermaid Diagrams Break in Confluence Cloud PDF/Word Exports (and How to Fix It)
Teams using Mermaid macros in Confluence Cloud frequently see blank boxes, clipped wide flowcharts, or dark-mode text disappearing on white paper when exporting pages to PDF or Word. Here is why that happens and how to avoid it.
1. Why Exports Turn Blank or Drop Macros
- Async browser rendering timing: Confluence's PDF/Word export pipeline does not wait indefinitely for heavy client-side Custom UI iframes.
-
Word export null-return failures: Macros without an explicit
adfExporthandler returning valid Atlassian Document Format (ADF) fail or render raw placeholders in Microsoft Word exports. - Dark-mode SVG colors: Diagrams styled for dark mode inherit light text strokes that become invisible on white PDF backgrounds.
2. The Export-Safe Pattern
- Pre-rasterize the Mermaid SVG onto an offscreen HTML5 canvas at 2× DPI using a Print-Neutral Light background when saving the macro.
- Scale wide diagrams proportionally to A4/Letter portrait width (~720pt logical width) so flowcharts never clip on page edges.
-
Return the stored PNG snapshot as an ADF
mediaSinglenode inadfExport, with a fault-toleranttry/catchand a MermaidcodeBlockfallback for Word exports.