Getting Started
Prerequisites
Section titled “Prerequisites”To run a React PDF Viewer component in an application, here is the basic system requirement:
- React version: >= 18.0
- React version: >= 19.0
Remark: If using TypeScript, it requires >= TypeScript 4.6.
React PDF Kit works not only with a React framework such as Next.js (App Router and Pages Router), Remix and Gatsby but also works well with other React.js UI libraries such as MUI, Ant Design and Chakra UI.
Although React PDF can run on most JavaScript module bundlers, it is more vigorously tested on Vite and Webpack.
Browser support
Section titled “Browser support”Starting from @react-pdf-kit/viewer@^2.0.0, we officially support PDF.js 5 and default to PDF.js 5.4.530.
As newer PDF.js versions rely on more modern browser APIs, minimum supported browser versions have changed. Please review the compatibility details below before choosing a PDF.js version.
Default (PDF.js 5.4.530)
Section titled “Default (PDF.js 5.4.530)”React PDF Kit v2.0.0 defaults to PDF.js 5.4.530.
| Chrome | Firefox | Edge | Safari | Safari iOS | Chrome Android |
|---|---|---|---|---|---|
| 126+ | 126+ | 126+ | 18.4+ | 18.4+ | 126+ |
Using PDF.js 4.10.38
Section titled “Using PDF.js 4.10.38”If you need broader browser compatibility, you can continue using PDF.js 4.10.38, which supports:
| Chrome | Firefox | Edge | Safari | Safari iOS | Chrome Android |
|---|---|---|---|---|---|
| 119+ | 115+ | 115+ | 17.4+ | 17.4+ | 126+ |
To change the version of PDF.js used, refer to Overriding Dependency guide.
Installation
Section titled “Installation”Install React PDF Kit
Section titled “Install React PDF Kit”There are a few ways you can install React PDF Kit, namely bun, npm, pnpm or yarn.
To install using bun, run:
bun add @react-pdf-kit/viewerRemark: From v2 onwards, a new NPM package is used. To install v1 of React PDF, please run with @pdf-viewer/react.
Caching of previous Worker version with bun
Section titled “Caching of previous Worker version with bun”To clear cache, try running bun pm cache rm to remove cache in the global cache directory. If the error remains, try executing the following steps:
rm bun.lockbrm -R node_modulesPlease ensure that you follow this step if you want to override pdfjs-dist version. After that, you may execute this command to install all dependencies again.
bun iTo install using npm, run:
npm install @react-pdf-kit/viewerTo install using pnpm, run:
pnpm add @react-pdf-kit/viewerTo install using yarn, run:
yarn add @react-pdf-kit/viewerInstallation Issues
Section titled “Installation Issues”Apple M series
Section titled “Apple M series”Since the default version of pdfjs-dist in React PDF requires the canvas package, you may need to manually add the canvas package for Apple M1 and later chipsets.
You may use Brew, a popular package manager to install the canvas dependencies:
$ brew install pkg-config cairo pangoPeer Dependencies
Section titled “Peer Dependencies”The React PDF Viewer component requires PDF.js (pdfjs-dist) as a peer dependency with a default version of 5.4.530.
You may override the default pdfjs-dist within React PDF Kit. For more information, refer to Dependency Override.
Bundler Compatibility
Section titled “Bundler Compatibility”pdfjs-dist v5 is ESM-only. Most modern bundlers handle this without any configuration:
- Vite — works out of the box
- Turbopack (Next.js 15+) — works out of the box
- Webpack 5 — works with proper ESM support enabled
Exception: Next.js 14 (Webpack). Next.js 14 has a known ESM interop bug that causes pdfjs-dist v5 to fail at module load time:
TypeError: Object.defineProperty called on non-objectIf you are using Next.js 14, override pdfjs-dist to v4, which supports both ESM and CommonJS. See Dependency Override for more information.