Appearance
Presentation Import
Bring external reference assets onto the Present canvas: image places a reference image, svg places a validated SVG, and pdf places a PDF (each page vectorized to SVG) onto the current Present sheet, returning the created canvas shape ids. Accessed via snaptrude.presentation.import.
Both methods are host API calls that return Promises and write to the Present canvas — each call creates one or more canvas shapes and returns their ids. The host engine takes a browser File, which a plugin worker cannot supply, so these methods accept a url or dataUrl that the host adapts into a File.
At a glance
| Method | What it does | Mutates? |
|---|---|---|
image(source, options?) | Place a reference image on the current Present sheet | ✓ |
svg(source, options?) | Place a validated SVG on the current Present sheet | ✓ |
pdf(source, options?) | Place a PDF on the current Present sheet, one vector SVG shape per page | ✓ |
Present mode required
Every method in this namespace needs Present mode open. image, svg, and pdf throw if Present mode is not open or the source cannot be loaded.
Types
PluginPresentationImportResult
Result of an import.
| Property | Type | Description |
|---|---|---|
shapeIds | string[] | Ids of the created canvas shapes (one per page for PDFs) |
Functions
image(source, options?)
Import a reference image onto the current Present sheet.
- Parameters:
source:{ url?: string; dataUrl?: string }— the image to import; provide exactly one of:source.url:string(optional) — URL of the imagesource.dataUrl:string(optional) — base64 data URL of the image
options:{ position?: { x: number; y: number } }(optional)options.position:{ x: number; y: number }(optional) — where to place the image on the sheet
- Returns:
PluginPresentationImportResult— the createdshapeIds. - Throws: If Present mode is not open or the source cannot be loaded.
ts
// From a URL, at a chosen spot on the sheet
const { shapeIds } = await snaptrude.presentation.import.image(
{ url: "https://example.com/site-photo.png" },
{ position: { x: 200, y: 150 } }
);
console.log(shapeIds);
// Or from a base64 data URL
const fromData = await snaptrude.presentation.import.image({
dataUrl:
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
});
console.log(fromData.shapeIds);svg(source, options?)
Import an SVG onto the current Present sheet as a vector asset. Unlike image (which decides vector-vs-raster off the file's mime type and would rasterize an SVG served as text/plain), svg validates the source really is an SVG and forces the vector mime type.
Rendering is vector up to a complexity cap. Simple SVGs (up to ~1500 SVG element nodes and ~2 MB) render true-vector and stay crisp at every zoom. Beyond that cap the shared canvas renderer intentionally falls back to a 1920px raster to protect canvas performance, so very complex SVGs can look rasterized when zoomed in. The stored asset is the original SVG either way; only the on-canvas rendering falls back.
- Parameters:
source:{ url?: string; dataUrl?: string }— the SVG to import; provide exactly one ofsource.url/source.dataUrloptions:{ position?: { x: number; y: number } }(optional) — where to place the shape on the sheet
- Returns:
PluginPresentationImportResult— the createdshapeIds. - Throws: If Present mode is not open, the source cannot be loaded, or the source is not an SVG.
ts
const { shapeIds } = await snaptrude.presentation.import.svg({
url: "https://example.com/north-arrow.svg"
});pdf(source, options?)
Import a PDF onto the current Present sheet, placing one shape per page. Each page is converted to vector SVG and placed as a canvas shape.
- Parameters:
source:{ url?: string; dataUrl?: string }— the PDF to import; provide exactly one of:source.url:string(optional) — URL of the PDFsource.dataUrl:string(optional) — base64 data URL of the PDF
options:{ position?: { x: number; y: number } }(optional)options.position:{ x: number; y: number }(optional) — where to place the pages on the sheet
- Returns:
PluginPresentationImportResult— one shape id per page. - Throws: If Present mode is not open or the source cannot be loaded.
ts
const { shapeIds } = await snaptrude.presentation.import.pdf({
url: "https://example.com/plans.pdf"
});
console.log(`Placed ${shapeIds.length} pages on the sheet`);Errors
Failed calls reject with a typed PluginError — see Error Handling. Conditions specific to this namespace:
| Code | Thrown by | When | details |
|---|---|---|---|
VALIDATION | image, pdf | source does not carry exactly one non-empty url or dataUrl | issues |
PRECONDITION_FAILED | image, pdf | Present mode is not open | — |
OPERATION_FAILED | image, pdf | The source could not be fetched (network/CORS, malformed data URL) | url or source |
OPERATION_FAILED | pdf | PDF-to-SVG conversion failed (invalid or password-protected PDF) | — |
OPERATION_FAILED | image, pdf | No canvas shapes were created — the source is not a supported asset (png/jpeg/gif/svg image, or a valid PDF for pdf) | — |