HTML Export
Export Polotno designs to HTML from plain design JSON
Overview
The @polotno/html-export package converts a Polotno design into an HTML
string. It works directly on plain design JSON: no running editor or store
instance is required: so you can export a saved design, or export from a
page that never mounts the full editor.
The exporter is browser-first: it renders through the DOM, so it runs best in the browser. It can run server-side in Node under jsdom (see Using in Node), but with some fidelity trade-offs; for pixel-accurate server-side rendering use polotno-node.
Replaces store.toHTML()
This standalone package is the recommended way to export HTML. The editor's
store.toHTML() / store.saveAsHTML() methods are deprecated and now delegate
to jsonToHTML internally: migrate to the package directly.
Installation
npm install @polotno/html-exportBasic Usage
Pass the design JSON (from store.toJSON(), a saved file, or any source) to
jsonToHTML:
import { jsonToHTML } from '@polotno/html-export';
const html = await jsonToHTML(store.toJSON());jsonToHTML returns a Promise<string> containing the rendered HTML.
API Reference
jsonToHTML(json, options?)
Renders a Polotno design into an HTML string.
Parameters:
json(required): plain design JSON (e.g. fromstore.toJSON()).options(optional):elementHook({ dom, element }): post-process each element's virtual node before it is serialized.domis a lightweight JSX-like object withtype,props, andchildren; mutate and return it.textOverflow: how text taller than its box is handled:'change-font-size'(default, shrinks the font to fit),'resize', or'ellipsis'.textSplitAllowed:boolean(defaultfalse); whether shrink-to-fit measurement may wrap a long word mid-word.
import { jsonToHTML } from '@polotno/html-export';
const html = await jsonToHTML(store.toJSON(), {
elementHook: ({ dom, element }) => {
// add a custom class to every element
dom.props.className = `element-${element.type}`;
return dom;
},
});jsonToDOM(json, options?)
Same as jsonToHTML but returns the DOM tree instead of a serialized string, useful when you want to mount or further manipulate the result in the browser.
Using in Node
In Node, run the exporter under jsdom to provide the DOM it needs:
import { JSDOM } from 'jsdom';
import { jsonToHTML } from '@polotno/html-export';
const dom = new JSDOM();
global.document = dom.window.document;
global.window = dom.window;
const html = await jsonToHTML(designJson);Full-fidelity Node rendering
Under jsdom, font shrink-to-fit measurement is a no-op and per-line text
backgrounds fall back to a legacy overlay (real Range.getClientRects is
required). For pixel-accurate rendering in Node with real Chromium, use
polotno-node.
Limitations
Not pixel-perfect
HTML export may not reproduce every element or effect exactly. For
pixel-perfect output use PNG/JPEG (store.toDataURL()) or PDF export.
If you hit a missing feature, share it in the Polotno Community.