Export API

Design on Web supports exporting designs to multiple file formats. Built-in formats (PNG, JPEG, WebP) work out of the box. Additional formats (SVG, PDF, PSD, TIFF) require registering export plugins.

Basic Export

Basic Exporttypescript
// Export to PNG (built-in, no plugin required)
const pngBlob = await engine.exportAs('png');

// Export with options
const hiResBlob = await engine.exportAs('png', {
  multiplier: 2,        // 2x resolution (2160x2160 for a 1080x1080 canvas)
  backgroundColor: null, // Transparent background
});

// Export to JPEG with quality
const jpegBlob = await engine.exportAs('jpeg', {
  quality: 0.85,
  multiplier: 1,
});

// Export to WebP
const webpBlob = await engine.exportAs('webp', {
  quality: 0.9,
});

Export Options

ExportOptions

NameTypeDefaultDescription
qualitynumber0.92Image quality from 0 to 1. Only applies to JPEG and WebP formats. Has no effect on PNG, SVG, PDF, or PSD.
multipliernumber1Resolution scale factor from 1 to 4. A value of 2 exports at double the canvas resolution. Applies to raster formats (PNG, JPEG, WebP, TIFF).
backgroundColorstring | nullOverride the canvas background color for export. Pass null for transparent background (PNG and WebP only).

Available Formats

Export Formats

NameTypeDefaultDescription
pngBuilt-inLossless raster format. Supports transparency. Best for graphics with sharp edges and text.
jpegBuilt-inLossy raster format. Smaller file sizes. Best for photographs. No transparency support.
webpBuilt-inModern raster format. Good compression with transparency support. Supported by all modern browsers.
svg@design-on-web/export-svgVector format. Scalable to any size without quality loss. Best for logos and illustrations.
pdf@design-on-web/export-pdfDocument format. Ideal for print-ready designs. Preserves vector data where possible.
psd@design-on-web/export-psdAdobe Photoshop format. Preserves layers. Best for designs that need further editing in Photoshop.
tiff@design-on-web/export-imageLossless raster format. Common in print workflows. Large file sizes.
jsonBuilt-inSerialized canvas state. Use for saving and restoring designs. Not a visual format.

Export Plugins

Export plugins add support for formats beyond the built-in PNG, JPEG, and WebP. Each plugin is a separate npm package to keep the core bundle small. Register plugins after creating the engine:

Registering Export Pluginstypescript
import { PsdExportPlugin } from '@design-on-web/export-psd';
import { PdfExportPlugin } from '@design-on-web/export-pdf';
import { SvgExportPlugin } from '@design-on-web/export-svg';
import { ImageExportPlugin } from '@design-on-web/export-image';

// Register plugins after engine creation
await engine.registerPlugin(PsdExportPlugin);
await engine.registerPlugin(PdfExportPlugin);
await engine.registerPlugin(SvgExportPlugin);
await engine.registerPlugin(ImageExportPlugin);

// Now these formats are available:
const svgBlob = await engine.exportAs('svg');
const pdfBlob = await engine.exportAs('pdf');
const psdBlob = await engine.exportAs('psd');
const tiffBlob = await engine.exportAs('tiff');

Plugin Packages

NameTypeDefaultDescription
@design-on-web/export-svgSvgExportPluginAdds SVG export support.
@design-on-web/export-pdfPdfExportPluginAdds PDF export support. Uses jsPDF internally.
@design-on-web/export-psdPsdExportPluginAdds PSD (Photoshop) export support with layer preservation.
@design-on-web/export-imageImageExportPluginAdds TIFF export support.
💡
Plugin registration
Plugins can be registered at any time, not just during initialization. However, registering them early ensures the export dialog shows all available formats from the start.

Download to File

The exportAs method returns a Blob. To trigger a file download in the browser:

Download Helpertypescript
// Download a blob as a file
async function downloadDesign(format, filename) {
  const blob = await engine.exportAs(format, { multiplier: 2 });
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = filename;
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
  URL.revokeObjectURL(url);
}

// Usage
await downloadDesign('png', 'my-design.png');
await downloadDesign('pdf', 'my-design.pdf');
await downloadDesign('psd', 'my-design.psd');

Upload to Server

Export and upload the result to your backend using FormData:

Upload to Servertypescript
// Export and upload to server
async function exportAndUpload(format) {
  const blob = await engine.exportAs(format);

  const formData = new FormData();
  formData.append('file', blob, `design.${format}`);

  const response = await fetch('/api/upload', {
    method: 'POST',
    body: formData,
  });

  const { url } = await response.json();
  console.log('Uploaded to:', url);
}

JSON Serialization

Use the json format or the toJSON() / loadJSON() methods for saving and restoring designs:

JSON Save/Loadtypescript
// Export as JSON (serialized canvas state)
const jsonBlob = await engine.exportAs('json');

// Or use toJSON() for a string directly
const jsonString = engine.toJSON();
localStorage.setItem('myDesign', jsonString);

// Restore later
const saved = localStorage.getItem('myDesign');
if (saved) {
  await engine.loadJSON(saved);
}
ℹ️
JSON vs other formats
JSON export preserves the full editable state — all objects, pages, layers, and settings. Other formats produce flat output files. Use JSON for save/load workflows and other formats for final output.

Export Events

Listen to export lifecycle events for progress tracking and error handling:

Export Eventstypescript
const eventBus = engine.getEventBus();

// Track export progress
eventBus.on('export:start', (data) => {
  console.log(`Exporting as ${data.format}...`);
  showLoadingSpinner();
});

eventBus.on('export:complete', (data) => {
  console.log(`Export complete: ${data.format}, ${data.blob.size} bytes`);
  hideLoadingSpinner();
});

eventBus.on('export:error', (data) => {
  console.error(`Export failed: ${data.error.message}`);
  hideLoadingSpinner();
  showErrorNotification(data.error.message);
});

Built-in Export Dialog

The EditorShell UI includes a built-in export dialog that provides a user-friendly interface for exporting designs. The dialog includes:

  • Format picker — dropdown to select the output format (shows all registered formats)
  • Quality slider — adjusts JPEG/WebP quality (hidden for lossless formats)
  • Scale dropdown — choose 1x, 2x, 3x, or 4x resolution
  • Preview — live preview of the exported result
  • Download button — triggers the file download

The dialog is accessible from the toolbar export button. No additional code is needed if you use EditorShell.

Next Steps