Getting Started
Prerequisites
Section titled “Prerequisites”To run a PDF Viewer component in a React.js 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 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”React PDF component is supported in modern browsers as follow:
| Chrome | Firefox | Edge | Safari | Safari iOS | Chrome Android |
|---|---|---|---|---|---|
| 115+ | 115+ | 115+ | 16.5+ | 16.5+ | 126+ |
Installation
Section titled “Installation”Install React PDF
Section titled “Install React PDF”There are a few ways you can install React PDF, namely bun, npm, pnpm or yarn.
To install using bun, run:
bun add @pdf-viewer/reactCaching 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 @pdf-viewer/reactTo install using pnpm, run:
pnpm add @pdf-viewer/reactTo install using yarn, run:
yarn add @pdf-viewer/reactInstallation 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”React PDF requires PDF.js as a peer dependency with a default version of 4.10.38. You may override the default pdfjs-dist but using version 3.11.174 or below could affect the functionalities of React PDF.
For more infomration, refer to Overriding Depenency.