Skip to main content

Visio & DXF export

The @visuallyjs/browser-ui-export package is an optional add-on for exporting a live Diagram to Visio (.vsdx) and AutoCAD DXF. For SVG, PNG, and JPEG export, see SVG, PNG and JPG export.

Setup​

Install @visuallyjs/browser-ui-export alongside the matching version of @visuallyjs/browser-ui:

npm install @visuallyjs/browser-ui-export

Create an Exporter instance with a Diagram:

How to access the diagram

To access the underlying Diagram in a React app, declare a ref and then use the getDiagram() method on it:



import { DiagramComponent } from "@visuallyjs/browser-ui-react"
import "@visuallyjs/browser-ui/css/visuallyjs.css"
import {useRef} from "react"

export default function App() {

const diagramRef = useRef(null)

const data = { ... }

const options = {...}

function doSomething() {
const diagram = diagramRef.current.getDiagram()
// now you can invoke methods on "diagram"
}

return <div style={{width:"100%", height:"500px"}}>
<DiagramComponent data={data} options={options} ref={diagramRef}/>
</div>
}
import { Exporter } from "@visuallyjs/browser-ui-export"

const exporter = new Exporter(diagram)

Visio Export​

exporter.exportVisio() produces a single-page .vsdx archive (Blob) with editable SVG-derived outlines, independent edge routes, plain labels, and solid fills/strokes (grouped per node so styled parts move together). The page fits the drawing with a quarter-inch margin at 96 diagram units per inch.

const { blob, warnings } = exporter.exportVisio({
getVertexLabel: (vertex) => String(vertex.data.label ?? "")
})

// Trigger download as a .vsdx file
const url = URL.createObjectURL(blob)
  • getVertexLabel: Optional callback that supplies plain text for HTML-backed vertices (which are represented by their measured bounding rectangle).
  • warnings: Array of VisioExportWarning objects (code: "unsupported-geometry" | "unsupported-style" | "invalid-geometry" | "html-fallback" | "omitted-text") identifying any omitted or fallback content by drawing object.

exportVisio​

Export a .vsdx file for Visio.
Signature
exportVisio(options:VisioExportOptions)
Parameters
optionsVisioExportOptions
Return value
VisioExportResult
VisioExportOptions
Options for a Visio export.
NameTypeDescription
getVertexLabel?(vertex:ExportVertex) => string | undefinedSupplies text for an HTML-backed vertex represented by its bounding rectangle.

AutoCAD DXF Export​

exporter.exportDxf(options?) synchronously generates AutoCAD 2007 DXF text from a rendered Diagram. Coordinates preserve the diagram origin, flip the Y axis for CAD space, and ignore viewport pan and zoom.

const { dxf, warnings } = exporter.exportDxf({
units: "mm",
scale: 0.5
})

const file = new Blob([dxf], { type: "application/dxf" })

The exporter writes editable lines, circles, polylines, and single-line text onto four CAD layers: NODES, GROUPS, EDGES, and LABELS. HTML vertices export their measured outlines, port outlines, plain text, and supported inline SVG.

exportDxf​

Export a DXF file.
Signature
exportDxf(options:DxfExportOptions)
Parameters
optionsDxfExportOptions
Return value
DxfExportResult
DxfExportOptions
Options for a DXF export
NameTypeDescription
curveTolerance?numberHow closely to fit curves. Defaults to 0.25.
renderVertex?(vertex:ExportVertex) => | undefinedOptional vertex exporter override function. Implement this if you want to provide custom behaviour for the export of your vertices.
scale?numberScale to use. Defaults to 1.
units?"unitless" | "in" | "ft" | "mm" | "cm" | "m"Units to use in the DXF. Defaults to "unitless".

Invalid options throw a RangeError. Any omitted content (such as clipping paths, masks, SVG <use> references, raster images, or rich labels) is reported in warnings (DxfExportWarning[]) with the owning node, group, or edge ID.