How to build a React.js PDF viewer with Nutrient

Table of contents

    Need to embed a fast, modern PDF viewer in your React app? This tutorial walks you through how to set up Nutrient’s commercial React.js PDF viewer using Vite. You’ll learn how to install the SDK, display a PDF file, and unlock features like annotations, digital signatures, and document editing — all inside a polished, production-ready user interface (UI).
    How to build a React.js PDF viewer with Nutrient
    Summary

    This step-by-step guide shows you how to build a PDF viewer in React using Nutrient Web SDK. You’ll set up a React app using Vite, install the SDK, and display a PDF with full viewer controls.

    • Modern tech stack — Vite + React + WebAssembly-based viewer
    • Supports PDF, DOCX, and image formats — View and annotate files client-side
    • Prebuilt UI — Includes 30+ features like comments, highlights, signatures, and redaction
    • Secure and scalable — Built for enterprise workflows with CSP, encryption, and compliance support
    • Fast to integrate — Load a document in fewer than 10 lines of code

    Perfect for apps that need a reliable, production-grade PDF viewer with advanced capabilities.

    The video tutorial above uses create-react-app. We now recommend using Vite, as detailed below.

    What is a React PDF viewer?

    A React PDF viewer lets you render and view PDF documents in a web browser without the need to download it to your hard drive or use an external application like a PDF reader.

    Nutrient React PDF viewer

    We offer a commercial React.js PDF viewer library that can easily be integrated into your web application. It comes with 30+ features that let you view, annotate, edit, and sign documents directly in your browser. Out of the box, it has a polished and flexible UI that you can extend or simplify based on your unique use case.

    • A prebuilt and polished UI for an improved user experience
    • 15+ prebuilt annotation tools to enable document collaboration
    • Support for more file types with client-side PDF, MS Office, and image viewing
    • Dedicated support from engineers to speed up integration

    Example of our React.js PDF viewer

    To demo our React.js PDF viewer, upload a PDF, JPG, PNG, or TIFF file by selecting Open Document. Once your document is displayed in the viewer, try drawing freehand, adding a note, or applying a crop or an eSignature.

    Requirements to get started

    To get started, you’ll need:

    Setting up a new React project with Vite

    Use vite(opens in a new tab) to scaffold out a simple React application:

    Terminal window
    npm create vite@latest nutrient-react-example -- --template react
    cd nutrient-react-example

    Install Nutrient Web SDK

    Next, install the @nutrient-sdk/viewer package:

    Terminal window
    npm i @nutrient-sdk/viewer

    Copying SDK assets to the public directory

    Nutrient Web SDK loads its WebAssembly and supporting files from a local path, so you need to copy them to the public folder. Start by installing the required copy plugin:

    Terminal window
    npm install -D rollup-plugin-copy

    Then, update your Vite config (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(),
    ],
    });

    Displaying a PDF

    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;
    let cleanup = () => {};
    (async () => {
    const NutrientViewer = (await import("@nutrient-sdk/viewer")).default;
    // Unload any previous instance.
    NutrientViewer.unload(container);
    if (container && NutrientViewer) {
    NutrientViewer.load({
    container,
    document: "/example.pdf",
    baseUrl: `${window.location.protocol}//${
    window.location.host
    }/${import.meta.env.PUBLIC_URL ?? ""}`,
    });
    }
    cleanup = () => {
    NutrientViewer.unload(container);
    };
    })();
    return cleanup;
    }, []);
    return <div ref={containerRef} style={{ height: "100vh", width: "100vw" }} />;
    }
    export default App;

    You can also render a different file by changing the document path or making it dynamic.

    Once everything is configured, start your app:

    Terminal window
    npm run dev

    You’ll now see the Nutrient Web SDK UI rendering your PDF inside the browser!

    Note that because Nutrient is a commercial product, you’ll see a Nutrient Web SDK evaluation notice on the document. To get a license key, contact Sales.

    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.js guides:

    Conclusion

    You should now have our React PDF viewer up and running in your web application. If you hit any snags, don’t hesitate to reach out to our Support team for help.

    You can also deploy our vanilla JavaScript PDF viewer or use one of our many web framework deployment options like Vue.js, Angular, and jQuery. To see a list of all web frameworks, start your free trial. Or, launch our demo to see our viewer in action.

    Hulya Masharipov

    Hulya Masharipov

    Technical Writer

    Hulya is a frontend web developer and technical writer at Nutrient who enjoys creating responsive, scalable, and maintainable web experiences. She’s passionate about open source, web accessibility, cybersecurity privacy, and blockchain.

    Explore related topics

    FREE TRIAL Ready to get started?