Back to homepage

CAD + EMF Export in One Pipeline

Generate DWG/DXF for CAD consumers and EMF/EMF+ for Windows-native vector interchange from a single IR extraction.

Code

import { extractIR, renderIR, DWGWriter, AcadDXFWriter, EMFWriter, EMFPlusWriter } from "@node-projects/layout2vector"; async function exportCadAndMetafile(root) { const bounds = root.getBoundingClientRect(); const maxY = Math.ceil(bounds.height); const ir = await extractIR(root, { includeText: true, includeImages: true, includePseudoElements: true, svgToVector: true }); const dwgBytes = await renderIR(ir, new DWGWriter({ maxY })); const dxfBytes = await renderIR(ir, new AcadDXFWriter({ maxY })); const emfBytes = await renderIR(ir, new EMFWriter({ width: bounds.width, height: bounds.height })); const emfPlusBytes = await renderIR(ir, new EMFPlusWriter({ width: bounds.width, height: bounds.height })); return { dwgBytes, dxfBytes, emfBytes, emfPlusBytes }; }

Notes

If exact browser webfont appearance is required for CAD/EMF-family outputs, pre-process IR text nodes with rasterizeFontTextNodes() and use the rasterized IR for those writers.