Message API/docs/components/files/export

Export & Print

Generate downloadable versions of documents or trigger browser-native print flows.

Overview

File Export allows your application to command the viewer to generate a persistent version of the current session. This includes all active markups, measurements, and annotations.

The process is asynchronous: you dispatch an export request, and the viewer notifies your application when the file is ready for download.

  • Asynchronous Processing: High-speed document generation without blocking the UI.
  • Markup Integration: Exported files include all interactive annotations and measurements.
  • Secure URLs: Receive temporary, direct-download links for the resulting files.

Quick Examples

Trigger an export and handle the completion event.

Request export

iframe.contentWindow.postMessage({ type: 'export' }, viewerOrigin);

Handle exportComplete

window.addEventListener('message', (event) => {
  if (event.data.type === 'exportComplete') {
    window.open(event.data.payload.fileUrl, '_blank');
  }
});

Control flow

Document generation follows a command-event pattern. You initiate the process from your application, and the viewer responds with the resulting file link.

Host Sends

1. Host Requests Export

Send the export message to the viewer to start the document generation process.

javascript
// 1. Get a handle to the viewer iframe
const iframe = document.querySelector('[data-viewer-iframe]');

// 2. Command the viewer to export the current state
iframe.contentWindow.postMessage({
  type: 'export'
}, '*');
Canvas Emits

2. Viewer Returns Link

The viewer emits the exportComplete event once the file is ready for download.

javascript
// Listen for export completion
window.addEventListener('message', (event) => {
  if (event.data.type === 'exportComplete') {
    const { fileUrl } = event.data.payload;
    console.log(`Export ready: ${fileUrl}`);
    // Example: Open in new tab
    window.open(fileUrl, '_blank');
  }
});

Printing

Printing allows users to generate a high-quality print preview of the active document with all markups and annotations rendered.

  • Browser Native: Triggers the standard browser print dialog for the current document view.
  • Wysiwyg: Marks up and annotations are preserved exactly as shown on the canvas.

Request Print

iframe.contentWindow.postMessage({ type: 'print' }, '*');

Complete Implementation

Request an export and open the resulting file when it is ready.

const VIEWER_ORIGIN = 'https://your-canvas-domain.com';
const iframe = document.querySelector('[data-viewer-iframe]');

function requestExport() {
  iframe.contentWindow.postMessage({ type: 'export' }, VIEWER_ORIGIN);
}

window.addEventListener('message', (event) => {
  if (event.origin !== VIEWER_ORIGIN) return;
  if (event.data.type === 'exportComplete') {
    window.open(event.data.payload.fileUrl, '_blank');
  }
});
Complete Implementation

Live Preview

Try the interactive preview below to generate an export and capture the completion event.

Interactive Workbench

File export preview

Trigger an export and review the resulting file URL as soon as it is ready.

Additional Resources

Explore related file workflows and payload references.