Rasterex API/docs/getting-started/viewer-session

Canvas Session

Start a document canvas session with a supported file loading message.

URL payload shape

Send view after the iframe loads to open a publicly accessible file URL.

// 1. Send the message
window.postMessage({
  type: 'VIEWER_ACTION',
  method: 'view',
  payload: {
  "fileUrl": "<YOUR_FILE_URL>"
}
}, '*');
URL payload shape

URL payload with metadata

Use viewAny when you need to provide file metadata. displayName must include the file extension.

// 1. Send the message
window.postMessage({
  type: 'VIEWER_ACTION',
  method: 'viewAny',
  payload: {
  "fileUrl": "<YOUR_FILE_URL>",
  "displayName": "<FILE_NAME_WITH_EXTENSION>",
  "cacheId": "<CACHE_ID>",
  "mime": "<MIME_TYPE>"
}
}, '*');
URL payload with metadata

Local file payload

Use viewFile when the document comes from a browser file input. The payload is the actual File object.

// 1. Send the message
window.postMessage({
  type: 'VIEWER_ACTION',
  method: 'viewFile',
  payload: "<File>"
}, '*');
Local file payload

Send after iframe load

Post the view message from the host once the iframe reports load.

// 1. Get a handle to the viewer iframe (e.g. via ref or selector)
const iframe = document.querySelector('[data-viewer-iframe]');

// 2. Wait for the iframe to load before sending messages
iframe.addEventListener('load', () => {
  iframe.contentWindow?.postMessage(
    {
      type: 'view',
      payload: {
        fileUrl: '<YOUR_FILE_URL>',
      },
    },
    viewerOrigin,
  );
});
Send after iframe load