Canvas Quick Start
Embed the canvas, open a document, track loading, and send your first command.
This starter page gives you the smallest useful host integration. It mounts the canvas iframe, opens a PDF, shows loading status, and sends basic navigation commands.
CANVAS_URL:https://beta.viewer.viewsoft.com.FILE_URL:https://res.cloudinary.com/dvgeew3bj/image/upload/v1779169700/Main_version_1.pdf_1_ifrgjq.pdf.viewerOrigin: the trusted origin used for postMessage.
The complete example is intentionally plain HTML, CSS, and JavaScript. Frameworks can wrap the same logic later, but the integration contract stays the same.
- 1Create the iframe without
srcso JavaScript can attach the firstloadhandler safely. - 2Assign
iframe.src = CANVAS_URLafter the handler is attached. - 3Send the first
viewmessage withFILE_URLafter the canvas has had a moment to register its message listener. - 4Use
progressStartandprogressEndto update host UI.
This is the full flow in one file. The important part is the order: register listeners, set iframe src, wait briefly after load, then send the view message.
The common first-run bug is sending the view message too early. Create the iframe without src, register the load and message handlers, then assign iframe.src = CANVAS_URL.
After the iframe load event, wait briefly before sending the first view message. If progressStart does not arrive, retry once. This protects the first load without creating an endless message loop.
Validate the event origin before reading canvas messages. Use these events to update host loading UI and to know whether the first view message was received.
These are the first messages most integrations need. Keep the helper function small and reuse it for every command.
Before moving into the full API docs, verify these integration basics.
- Do not put
srcin the iframe markup if your script depends on catching the first load event. - Do not use
*as the target origin in production. - Make sure FILE_URL is reachable from the canvas environment.
Initialize Canvas
Embed the iframe and dispatch the first view payload.
Viewer Session
Pass session metadata and keep canvas state aligned.
Navigation API
Control zoom, fit, rotate, magnify, and text search.
File Export
Trigger export, print, and download workflows.
Annotation API
Create, select, delete, and inspect annotations.
Measurement API
Control measurement tools, scale, and extraction.
After the file opens, move into the API areas that match your workflow.
