Skip to content

Instance API

The component instance obtained through bind:this implements PowerPointViewerApi: the shared cross-binding viewer contract (the same one behind React's ref handle and Vue's defineExpose) plus the Svelte binding's editing and export methods. All toolbar operations are also available as instance methods, so you can hide the chrome (showToolbar={false}, showThumbnails={false}) and drive the viewer from your own UI.

svelte
<script lang="ts">
	import { PowerPointViewer, type PowerPointViewerApi } from 'pptx-svelte-viewer';

	let { bytes }: { bytes: Uint8Array } = $props();
	let viewer = $state<PowerPointViewerApi>();
</script>

<PowerPointViewer source={bytes} bind:this={viewer} />

Snapshots, not stores

The getter methods (canUndo(), getZoom(), getSelectedElementIds(), ...) return plain snapshots; they are not reactive stores. To react to changes, use the callback props (onzoomchange, onselectionchange, ondirtychange, ...) from Component Props.

Serialisation

MethodSignatureDescription
getContent() => Promise<Uint8Array>Serialise the current presentation to .pptx bytes (alias of save()).
MethodSignatureDescription
goTo(index: number) => voidJump to a zero-based slide index (clamped).
goPrev() => voidGo to the previous slide.
goNext() => voidGo to the next slide.
getActiveSlideIndex() => numberZero-based index of the visible slide.
setActiveSlideIndex(index: number) => voidAlias of goTo.
getSlideCount() => numberNumber of slides in the loaded presentation.

Zoom

MethodSignatureDescription
getZoom() => numberEffective zoom scale (1 = 100%).
setZoom(level: number) => voidSet an explicit zoom scale (clamped).
zoomIn() => voidZoom in by one step.
zoomOut() => voidZoom out by one step.
zoomReset() => voidReset zoom to 100%.

Mode and presentation

MethodSignatureDescription
getMode() => ViewerModeCurrent mode: 'preview' | 'edit' | 'present' | 'master'.
setMode(mode: ViewerMode) => voidSwitch mode. 'present' enters fullscreen presentation (real Fullscreen API); any other mode exits it. 'edit' and 'master' imply editing.
ts
viewer?.setMode('present'); // start presenting; Esc exits

Slide access and manipulation

MethodSignatureDescription
getSlides() => readonly PptxSlide[]The full slide array (snapshot with full type information).
getSlide(index: number) => PptxSlide | undefinedA single slide by zero-based index.
getActiveSlide() => PptxSlide | undefinedThe currently active slide.
addSlide(afterIndex?: number) => voidAdd a blank slide after the given index (or at the end).
deleteSlides(indexes: number[]) => voidDelete slides by index (at least one slide is kept).
duplicateSlides(indexes: number[]) => voidDuplicate slides at the given indexes.
moveSlide(fromIndex: number, toIndex: number) => voidMove a slide to a new position.
toggleHideSlides(indexes: number[]) => voidToggle the hidden flag on slides.
isDirty() => booleanWhether the document has unsaved changes.

Element access and manipulation

MethodSignatureDescription
getElements(slideIndex?: number) => readonly PptxElement[]Elements on a slide (defaults to the active slide).
getElementById(id: string, slideIndex?: number) => PptxElement | undefinedA single element by id.
updateElement(id: string, updates: Partial<PptxElement>) => voidPatch element properties, e.g. { x: 100, width: 300 }.
deleteElements(ids: string[]) => voidDelete elements by id from the active slide.
duplicateElement(id: string) => string | undefinedDuplicate an element; returns the new element's id.

Selection

MethodSignatureDescription
getSelectedElementIds() => string[]Ids of the currently selected elements.
selectElements(ids: string[]) => voidProgrammatically select elements.
clearSelection() => voidClear the selection.
getSelectedElementId() => string | nullThe selected top-level element id, or null.

Editing

Active when editable is set (see Getting Started > Editing).

MethodSignatureDescription
undo() => voidUndo the last committed edit.
redo() => voidRedo the last undone edit.
canUndo() => booleanWhether an undo step is available (snapshot; not reactive).
canRedo() => booleanWhether a redo step is available.
deleteSelected() => voidDelete the selected element (no-op when nothing is selected).
save(format?: PptxSaveFormat) => Promise<Uint8Array>Serialise the edited slides to bytes ('pptx' | 'ppsx' | 'pptm').
downloadAs(format: PptxSaveFormat, fileName?: string) => Promise<void>Save + trigger a browser download in the given format.
downloadPptx(fileName?: string) => Promise<void>Save + download as .pptx (default name).
packageForSharing(fileName?: string) => Promise<void>Assemble and download the sharing package.

Keyboard shortcuts, active whenever editing is enabled: Ctrl/Cmd+Z undo, Ctrl/Cmd+Shift+Z redo, Delete/Backspace delete, Ctrl/Cmd+D duplicate, arrow keys nudge (with Shift for larger steps), Escape deselect.

Export and print

MethodSignatureDescription
exportSlidePng(index?: number) => Promise<void>Export a slide as a PNG download (defaults to the current slide).
copySlideAsImage(index?: number) => Promise<void>Copy a slide to the system clipboard as a PNG image.
exportPdf(options?: ExportPdfOptions) => Promise<void>Multi-page PDF download, one slide per page.
exportGif(options?: ExportGifOptions) => Promise<void>Animated GIF download.
exportVideo(options?: ExportVideoOptions) => Promise<void>WebM video download.
print(options?: PrintOptions) => Promise<boolean>Open the browser print dialog (slides / handouts / notes / outline).

See Export & Print for the option shapes, pipelines, and the standalone SVG export functions.

Example: external controls

svelte
<script lang="ts">
	import { PowerPointViewer, type PowerPointViewerApi } from 'pptx-svelte-viewer';

	let { bytes }: { bytes: Uint8Array } = $props();
	let viewer = $state<PowerPointViewerApi>();
	let current = $state(0);
	let count = $state(0);
</script>

<PowerPointViewer
	source={bytes}
	showToolbar={false}
	showThumbnails={false}
	bind:this={viewer}
	onload={({ slideCount }) => (count = slideCount)}
	onslidechange={(index) => (current = index)}
/>

<div>
	<button onclick={() => viewer?.goPrev()}>Prev</button>
	<span>Slide {current + 1} of {count}</span>
	<button onclick={() => viewer?.goNext()}>Next</button>
	<button onclick={() => viewer?.setMode('present')}>Present</button>
</div>

Lower-level building blocks

The pptx-svelte-viewer/viewer entry point additionally exports the viewer's internal framework-free state helpers (ViewerState, PresentationLoader, clampSlideIndex, fitScale, resolveNavigationKey, zoomInPercent, zoomOutPercent) for hosts building custom chrome on the same primitives. These are lower-level than the component API and not needed for typical embedding.

Released under the Apache-2.0 License.