@s8fy/pptx-viewer-react
v3.17.0
Published
React PowerPoint (PPTX) viewer adapter with typed props, controller refs and local PDF export through the shared viewer
Maintainers
Readme
@s8fy/pptx-viewer-react
Product · Framework guide · Viewer playground · Commercial licensing · Report an issue
High-fidelity PowerPoint viewing in React, powered by the shared PPTX viewer engine.
React adapter for @s8fy/pptx-viewer, with font-driven text layout, vector graphics, charts, and supported DrawingML effects. The adapter connects React lifecycle and refs to the shared viewer controller.
Key Features
- The shared viewer engine in React. Display native charts, SmartArt, styled tables, vector shapes, images, and supported Office equations with the same engine as the framework-neutral SDK.
- 3D and modern Office charts. Supported 3D column/bar, line, area, pie, and surface charts use projected geometry and selected scene settings, with approximate lighting. Waterfall, Funnel, Histogram, Treemap, Sunburst, and Box & Whisker have rendering paths, alongside classic chart families and selected 2D combinations. Formatting/layout coverage varies by family.
- Typography and DrawingML detail. Font-driven text layout, mixed styles, bullets, tabs, autofit, optional embedded fonts, glyph glow/reflections, shape inner shadows/reflections, and selected shape/text 3D profiles. SmartArt prefers cached drawings and supports selected uncached process/hierarchy layouts.
- Presentations that play. Supported object effects, selected slide transitions, Morph, click builds, fullscreen, presenter mode, and looping autoplay. Chart subtargets cover selected 2D column/bar series/categories/points and line/area series, excluding combination layers and charts with trendlines/error bars. Selected SmartArt nodes can animate independently. Playback defaults to fullscreen/presenter mode; enable inline animation explicitly when needed.
- Local viewing and PDF export. Supply PPTX bytes directly, self-host runtime/font assets, and disable remote fonts for offline deployments. PDF export runs locally from the original file and creates static pages.
- React lifecycle and imperative control. Typed props and a forwarded controller ref, controller reuse on source changes, callback updates without a reset, automatic cleanup on unmount, and SSR-safe module imports. Mount in a client component when using Next.js.
The adapter shares the Viewer's rendering engine and capability boundaries. Fonts, browser support, and the authored Office variant affect fidelity. Unsupported profiles use their applicable fallback; complete PowerPoint parity is not promised. Model-only sources cannot export the original file to PDF/PPTX, and commercial use requires a commercial license. See the shared capability details.
Install
pnpm add @s8fy/pptx-viewer @s8fy/pptx-viewer-react react react-dom@s8fy/pptx-viewer is a direct installation because the application imports its stylesheet.
Peer dependencies: React and React DOM 18 or 19. The package declares Node.js 22.12+ and includes ESM/CJS entrypoints with TypeScript declarations.
Usage
import { useMemo, useRef } from 'react'
import { PptxViewer } from '@s8fy/pptx-viewer-react'
import type { PptxViewerRef } from '@s8fy/pptx-viewer-react'
import type { ViewerSource } from '@s8fy/pptx-viewer'
import '@s8fy/pptx-viewer/style.css'
export function App({ file }: { file: ArrayBuffer }) {
const viewerRef = useRef<PptxViewerRef | null>(null)
const source = useMemo<ViewerSource>(() => ({ kind: 'file', file }), [file])
return (
<PptxViewer
ref={viewerRef}
source={source}
onLoad={({ total }) => console.log(`Loaded ${total} slides`)}
onError={(error) => console.error(error)}
/>
)
}PptxViewer accepts the same ViewerOptions as the facade plus className and style. Its forwarded ref exposes the imperative Viewer controller. The adapter only handles React lifecycle, props, events, and refs; rendering is delegated to the universal viewer controller. Module import is SSR-safe, while mounting requires a browser DOM.
Sources, updates, and cleanup
- Obtain bytes with
await file.arrayBuffer()orawait response.arrayBuffer()before passing them as props. A browserFileis not the source value. - Use
source={{ kind: 'presentation', presentation }}for a normalized model. Omitsourcefor an empty viewer. Top-levelfile,fileName, andpresentationprops are rejected. - Keep the
sourceobject stable between unrelated renders, as inuseMemoabove. A new source object triggers loading even if it contains the same bytes. Replace the source/model reference to apply changes; do not mutate model data in place. - Source changes reuse the controller. Configuration changes or removing a source recreate it. Callback changes alone do not reset it. Unmount automatically destroys it; the forwarded ref is cleared when a controller is replaced or unmounted.
The ref becomes available after mounting; it does not mean the initial file is loaded. Use onLoad for readiness, or omit the source prop and await viewerRef.current.load(buffer) when using imperative loading. Catch rejections from methods such as toPdf() and downloadPdf(). Model-only sources have no original-file PDF/PPTX export capability.
Callbacks such as onSlideChange(index) use zero-based indices; onPlaybackChange(playing) reports interactive play()/pause() state from the forwarded ref. React has no adapter-specific onReady prop; use the forwarded ref. Pass options directly, not through an options prop. Viewer parsing defaults to WASM; browser PDF export still requires WASM and Workers even if parsing uses JS.
In Next.js App Router, put the viewer in a client component ('use client'). Shared rendering capabilities, options, font configuration, methods, and error types are documented in the viewer README.
Review workspace
Import PptxWorkspaceViewer from @s8fy/pptx-viewer-react/workspace and render it with options={{ base, mode: 'review' }}. base contains an id, a snapshot descriptor, and the matching PPTX file as an ArrayBuffer. Pass onStateChange for current hits and a ref or onReady for navigation commands. The component disposes the workspace on unmount. The host manages its Review session and Writer separately.
Upgrading to 3.0
The ref's controller no longer has fullscreen(). Use await viewer.enterFullscreen() in a user interaction handler and handle its Promise<void> rejection; onError only notifies and does not consume the rejection. React component props and ref wiring are unchanged. Rendering, parsing, PDF export, and lifecycle behavior follow the shared Viewer 3.0.0 contract.
License
This adapter package is licensed under the MIT License. Its runtime dependency @s8fy/pptx-viewer is separately licensed under its own commercial and evaluation license.
