React file viewer: Display PDFs, images, and Office documents in your app
Table of contents
react-file-viewer and @cyntler/react-doc-viewer — haven’t kept up with modern Office formats and high-fidelity rendering. This post shows how to build a maintained React file viewer (and document viewer) with Nutrient Web SDK that opens PDFs, images, and DOCX/XLSX/PPTX directly in the browser — no server, no MS Office. See the live demo.
Build a React file viewer with Nutrient Web SDK to display PDF documents, images, and Office files entirely in the browser — no server or Microsoft Office required. After creating a Vite-powered React project, you’ll install the SDK, copy its WebAssembly assets, and load any .pdf, .docx, .pptx, or image file with a single NutrientViewer.load() call. The same viewer unlocks text editing, page manipulation, annotations, and eSignatures out of the box.
React file viewer libraries compared
The two most-installed open source options haven’t kept up. Before you pick a library, here’s how the common choices line up:
| Library | Formats supported | Maintenance | License | Rendering |
|---|---|---|---|---|
react-file-viewer | PDF, images, CSV, XLSX, DOCX (limited) | Last npm release Nov 2019 | Apache-2.0 | Basic; Office formats are a thin wrapper |
@cyntler/react-doc-viewer | PDF, images, DOCX, CSV, XLSX | No longer maintained (last release Sep 2025; maintainer stepped away) | Apache-2.0 | Basic; relies on per-format renderers |
| Nutrient Web SDK | PDF, PDF/A, DOCX, DOC, XLSX, XLS, PPTX, PPT, TIFF, PNG, JPEG | Actively maintained | Commercial | High-fidelity, WebAssembly-based, no MS Office on backend |
If your app only ever needs a quick PDF preview, the open source options will work. If you need DOCX, XLSX, and PPTX rendered the way users expect — and a maintained library — read on.
Using Nutrient as a React document viewer
“React file viewer” and “React document viewer” are often used interchangeably. Nutrient Web SDK serves both: a single NutrientViewer.load() call renders any supported file by URL or buffer, and the same viewer instance handles PDFs and Office documents without switching renderers. The setup below gives you a production-ready React document viewer in a Vite project.
Why choose a React file viewer — And what it lets you do
A dedicated React file viewer lets users preview documents without extra downloads, keeps files entirely on the client side for better security, and cuts server costs. When you integrate Nutrient Web SDK, you unlock even more:
- Universal format coverage — PDF/A plus Office (DOCX, XLSX, PPTX) and images.
- Zero heavyweight dependencies — All conversion happens in the browser via WebAssembly.
- Deep document tooling
- Text editing directly inside Office files
- Page manipulation (reorder, add, or delete pages)
- Rich annotations (highlights, comments, stamps)
- eSignatures and form filling
- Redaction and document security features
Opening and rendering multiple file formats in the browser
Nutrient Web SDK brings support for PDF, image, and Office formats to your application, without you or your users needing any MS Office software, MS Office licenses, or third-party open source software. The technology works by converting an image (JPG, PNG, and TIFF) or Office document (Word, Excel, and PowerPoint) to PDF directly in the browser using our Office-to-PDF conversion engine. The resulting PDF is then rendered in our JavaScript viewer.
Requirements to get started
To get started, you’ll need:
- The latest version of Node.js(opens in a new tab).
- A package manager compatible with npm. This post contains usage examples for Yarn(opens in a new tab) and the npm(opens in a new tab) client (installed with Node.js by default).
Setting up a new React project with Vite
To get started, create a new React project using Vite:
Terminal window # Using Yarnyarn create vite nutrient-react-example --template react# Using npmnpm create vite@latest nutrient-react-example -- --template reactChange to the created project directory:
cd nutrient-react-example
Adding Nutrient to your project
Add the Nutrient dependency:
yarn add @nutrient-sdk/viewernpm install --save @nutrient-sdk/viewerNutrient Web SDK loads its WebAssembly and supporting files from a local path, so you need to copy them to the
publicfolder. Start by installing the required copy plugin:Terminal window npm install -D rollup-plugin-copy
Then, update your Vite configuration (vite.config.ts) to copy the SDK’s asset files during build:
import { defineConfig } from "vite";import react from "@vitejs/plugin-react";import copy from "rollup-plugin-copy";
export default defineConfig({ plugins: [ copy({ targets: [ { src: "node_modules/@nutrient-sdk/viewer/dist/nutrient-viewer-lib", dest: "public/", }, ], hook: "buildStart", }), react(), ],});Need DOCX, XLSX, and PPTX in your React app? Start a 30-day Nutrient trial. Render any supported format with one NutrientViewer.load() call.
Displaying a document
Nutrient supports the following file formats:
- PDF, PDF/A (1, 2, 3, 4)
- DOCX, DOC, DOTX, DOCM
- XLSX, XLS, XLSM
- PPTX, PPT, PPTM
- TIFF, TIF (including multipage)
- PNG, JPEG, JPG
Add your document to the
publicdirectory. You can use our demo PowerPoint document as an example.Now that everything is set up, you’ll render a PDF using the Nutrient SDK.
Basic usage in
App.tsx:import { useEffect, useRef } from "react";function App() {const containerRef = useRef(null);useEffect(() => {const container = containerRef.current;if (!container) return;let cancelled = false;let viewer: typeof import("@nutrient-sdk/viewer").default | null = null;(async () => {const NutrientViewer = (await import("@nutrient-sdk/viewer")).default;if (cancelled) return;viewer = NutrientViewer;// Unload any previous instance bound to this container.NutrientViewer.unload(container);try {await NutrientViewer.load({container,document: "slides.pptx", // The document to load.baseUrl: `${window.location.protocol}//${window.location.host}/${import.meta.env.PUBLIC_URL ?? ""}`,});// If the component unmounted while loading, unload immediately.if (cancelled) NutrientViewer.unload(container);} catch (error) {if (!cancelled) console.error("Failed to load document:", error);}})();return () => {cancelled = true;viewer?.unload(container);};}, []);return (<div ref={containerRef} style={{ height: "100vh", width: "100vw" }} />);}export default App;Start the app and run it in your default browser:
Terminal window # Using Yarnyarn dev# Using npmnpm run dev
Live demo
Interact with the sandbox by clicking the left rectangle icon and selecting Editor > Show Default Layout. To edit, sign in with GitHub — click the rectangle icon again and choose Sign in. To preview the result, click the rectangle icon once more and choose Editor > Embed Preview. For the full example, click the Open Editor button.
Viewing different file formats in React
The same NutrientViewer.load() call handles every supported format — only the document value changes. Each section below has the format-specific notes worth knowing before you ship.
Viewing DOCX files in React
DOCX (and DOC, DOTX, DOCM) is converted to PDF in the browser via WebAssembly, so you don’t need MS Word on the server. Pass the .docx URL straight to document:
NutrientViewer.load({ container, document: "contract.docx", baseUrl });For a deeper walkthrough, see the Nutrient Web SDK Word viewer guide.
Viewing XLSX files in React
XLSX (and XLS, XLSM) is converted to PDF in the browser using the same WebAssembly pipeline. Pass the file URL directly:
NutrientViewer.load({ container, document: "report.xlsx", baseUrl });For multisheet workbooks, set splitExcelSheetsIntoPages: true in the Office-to-PDF conversion options so each sheet becomes its own PDF page. See the Excel in the browser walkthrough for layout tips.
Viewing PPTX files in React
PPTX (and PPT, PPTM) loads directly — the example above already uses a slide deck. See the PowerPoint viewer guide for deck-specific options.
Viewing PDF and image files in React
PDFs (including PDF/A 1, 2, 3, 4) and images (PNG, JPEG, TIFF — multipage TIFFs supported) load with the same call. Images are converted to PDF on load, so annotation, redaction, and page manipulation work uniformly across formats:
NutrientViewer.load({ container, document: "scan.tiff", baseUrl });A note about fonts
In client-side web applications for Microsoft Office-to-PDF conversion, Nutrient addresses font licensing constraints through font substitutions, typically replacing unavailable fonts with their equivalents — like Arial with Noto. For precise font matching, you can provide your own fonts, embed them into source files, or designate paths to your .ttf fonts for custom solutions.
Adding even more capabilities
Once you’ve deployed your viewer, you can start customizing it to meet your specific requirements or easily add more capabilities. To help you get started, here are some of our most popular React guides:
Conclusion
In this blog post, you learned how to create a React file viewer using Nutrient Web SDK. It enables opening and viewing PDF, image, and Office files directly in the browser using client-side processing. No server is required.
If you’re looking for a way to render your documents in your web application, then Nutrient Web SDK is a great option. It’s a powerful and flexible library that can help you provide your users with a seamless and enjoyable experience.
To get started, you can either:
- Start your free trial to test the library and see how it works in your application.
- Launch our demo to see the viewer in action.
Related reading
- How to build a PowerPoint viewer in JavaScript — Display PPT/PPTX files in the browser with Nutrient
- Open Excel files in the browser using JavaScript — Handle XLS and XLSX files without MS Office
- How to build a React Word viewer — Display DOC/DOCX files in React applications
- Top five document viewers for developers — Compare DOCX and PDF viewer libraries side by side
FAQ
You can build a React.js file viewer using Nutrient Web SDK, which supports viewing PDFs, images, and Office files directly in the browser without requiring server-side processing.
Nutrient Web SDK supports PDF, PDF/A, DOCX, DOC, DOTX, DOCM, XLSX, XLS, XLSM, PPTX, PPT, PPTM, TIFF, PNG, JPEG, and JPG formats.
Create a new React app using Vite. Then add the Nutrient dependency via npm or yarn. Finally, copy the Nutrient library assets to your project’s public directory.
Yes, you can edit text, manipulate pages, add annotations, and include signatures in the documents displayed within the viewer.
Yes. You can customize the viewer to meet specific requirements by adding features like Instant synchronization, document assembly, page manipulation, forms, signatures, redaction, and document security.
No. Nutrient Web SDK enables client-side processing, so you don’t need a server to render documents in your React app.
Nutrient substitutes missing fonts with similar ones, like replacing Arial with Noto. For exact font matching, you can provide custom fonts by embedding them or setting paths to .ttf files.