This guide shows how to build a Next.js PDF viewer using the Apryse WebViewer SDK. You'll learn how to integrate the SDK into a Next.js application to render, view, and interact with PDF documents using the WebViewer UI. This guide uses JavaScript examples. TypeScript projects will require minor adjustments.
You can also download a ready-to-use GitHub sample to get started quickly, or explore the interactive Showcase demo to see WebViewer's full capabilities in action.
This guide assumes basic familiarity with Next.js development. Before you start:
Apryse collects some data regarding your usage of the SDK for product improvement.
If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.
In this section, you’ll create a new Next.js application using npm. This project provides the foundation for integrating Apryse WebViewer. If you already have an existing Next.js app, you can skip this step and continue to the Install WebViewer section.
webviewer-nextjs project using a minimal setup:Flags are used to skip prompts during project configuration. The setup uses JavaScript, skips ESLint configuration, disables React Compiler, excludes Tailwind CSS, omits the src/ directory, enables App Router, and accepts other defaults. Select different options if preferred.
3. Navigate to your new Next.js project directory and install dependencies:
Next, install the Apryse WebViewer SDK using npm. This command adds the WebViewer package to your project, allowing you to integrate the PDF viewer and editor into your Next.js application.
After navigating to your webviewer-nextjs project directory, run the following command to install WebViewer:
WebViewer needs access to its static assets at runtime, including WebAssembly modules, HTML, and CSS files. In a Next.js project, you must copy these assets into the public directory so they can be served correctly. For more, see Copying WebViewer static assets.
public/lib/webviewer directory if it doesn't already exist:2. Copy all WebViewer static assets from node_modules/@pdftron/webviewer/public into the new public/lib/webviewer directory:
Your project should now include a similar structure:
The path option used when initializing WebViewer must point to this directory (for example, /lib/webviewer). If the path is incorrect, WebViewer will fail to load.
In this section, you'll add WebViewer to your Next.js app by creating a component and initializing the viewer. This mounts the WebViewer UI and loads a document in your application.
1. Create a components folder in your project's root:
2. Create a webviewer.js file in the components folder:
3. In Visual Studio Code, add this code to the webviewer.js file and save:
components/webviewer.js
If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
4. Replace the contents of the app/page.js file with the following and save:
app/page.js
You can now load and display a PDF document in the WebViewer UI. Run your Next.js application to launch WebViewer and see the PDF in your browser.
1. From your project directory, run the following command to start the application:
A successful output looks similar to:
2. Open the localhost URL from your terminal to view the WebViewer UI and PDF document.
You may see a React hydration warning in the console when running the app locally. This is often caused by browser extensions modifying the page before React loads, not by your code. This warning is safe to ignore and doesn't affect WebViewer or PDF rendering. It will not appear in production.
You can suppress hydration warnings during development by overriding console.error — but we don’t recommend this unless you're absolutely sure hydration warnings are harmless.
In this video, learn how to install and integrate the Apryse WebViewer SDK into a Next.js project using TypeScript. You’ll set up the PDF viewer, enable content editing, and explore the DOCX and Spreadsheet Editors.
Integrate WebViewer in a Next.js project with PDF editing, DOCX Editor, and Spreadsheet Editor.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales