Back to homepage

One Extraction, Multiple Output Writers

Extract once, then fan out to several output formats. This keeps geometry and paint-order consistent across artifacts generated in a single run.

DXF SVG HTML PNG

Code

import { extractIR, renderIR, DXFWriter, SVGWriter, HTMLWriter, ImageWriter } from "@node-projects/layout2vector"; async function exportAll(root) { const bounds = root.getBoundingClientRect(); const ir = await extractIR(root, { includeText: true, includeImages: true, convertFormControls: true, includePseudoElements: true }); const dxf = await renderIR(ir, new DXFWriter({ maxY: Math.ceil(bounds.height) })); const svg = await renderIR(ir, new SVGWriter({ width: bounds.width, height: bounds.height })); const html = await renderIR(ir, new HTMLWriter({ width: bounds.width, height: bounds.height })); const image = await renderIR(ir, new ImageWriter({ width: bounds.width, height: bounds.height, scale: 2 })); await image.finalize(); const pngBytes = image.toBytes(); return { dxf, svg, html, pngBytes }; }

When this helps

Use this for workflows where engineering receives CAD output, product receives PDF/SVG previews, and support receives PNG snapshots from the same source DOM.