React-PDF 11: rendering existing PDFs in React, and why the PDF.js worker setup decides whether it works
Display PDFs in your React app as easily as if they were images.
At a glance
- What is it?
- wojtekmaj/react-pdf wraps PDF.js in Document and Page components for displaying PDFs in React apps. Version 11 raises the floor to React 19, Node.js 22.13.0, Chrome 125 and Safari 18, and most setup failures trace back to where and how the worker is configured.
- Who is it for?
- React-PDF is the right pick for a React 19 app that needs to show existing PDFs page by page with text and annotation layers, and it is free under MIT. It is the wrong pick for generating PDFs, which belongs to @react-pdf/renderer, and for projects pinned to older React or browsers below Chrome 125 and Safari 18, which should stay on a v10.x or earlier branch.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 6 days ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.
Star history
- wojtekmaj/react-pdf11,204 ★ · +30
| Repository | 2026-09-22 | 2026-11-22 |
|---|---|---|
| wojtekmaj/react-pdf | 11.2k | 11.2k |
30 Stars in the last 61 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
It displays PDFs and cannot create them
The project's own documentation opens by separating two packages with similar names. `react-pdf` is for displaying PDFs that already exist. If you want to build PDFs from React components, the package you want is `@react-pdf/renderer`, a separate project on npm.
The display model is simple to describe. You render a `<Document file="..." />` and place `<Page />` components inside it, one per page you want on screen. The `file` prop accepts a URL, base64 content, a `Uint8Array` and other forms, so the same component handles a PDF fetched from a server and one already loaded into memory. The viewer is meant to be wrapped in React `Suspense` and an Error Boundary, so loading and failure states need a place in your component tree before the first `<Document>` goes in.
Annotations and the text layer each need their own stylesheet import if you use them. These are separate imports from the component itself, so a viewer that renders pages can still be missing those layers' styles until you add them.
Version 11 sets a high floor for React, Node.js and browsers
The current documentation is written for the 11.x branch, released as v11.0.0 on 2026-09-10, after v10.5.0 on 2026-08-20 and v10.4.1 on 2026-02-25. The requirements moved with it. The latest React-PDF needs React 19 or later and Node.js 22.13.0 or newer. On the browser side it supports the latest versions of all major modern browsers, with a hard minimum of Chrome 125 and Safari 18, which includes iOS 18.
The practical consequence is that upgrading React-PDF can force an upgrade elsewhere. A project still on React 18 cannot take v11 at all and has to stay on an older line. Documentation for each previous branch is kept separately: v10.x, v9.x, v8.x and v7.x under `packages/react-pdf/README.md` on their branches, and v6.x and v5.x under the root `README.md`. You can also switch tags with the branch dropdown on GitHub to read the docs that match the version you have installed.
Preact projects can use React-PDF through `preact/compat`, provided it has `use` support.
Chrome 125 needs a URL.parse polyfill before React-PDF loads
Meeting the minimum browser version is not the same as working out of the box. Browsers between the minimum and the latest release may need polyfills, bundler transpilation and the legacy PDF.js worker. The concrete case given is Chrome 125, which lacks `URL.parse()`, an API PDF.js calls. The polyfill has to run before React-PDF initializes:
if (typeof URL !== 'undefined' && typeof URL.parse !== 'function') {
URL.parse = function (url, base) {
try {
return new URL(url, base);
} catch {
return null;
}
};
}This fixes one missing function and nothing more. Polyfilling `URL.parse` alone does not make React-PDF work in browsers below Chrome 125 or Safari 18. For anything older, the PDF.js browser compatibility FAQ on the mozilla/pdf.js wiki is the reference to check, not this snippet.
The worker setting is overwritten if it lives in another module
React-PDF does nothing until a PDF.js worker is provided. The recommended way is to resolve the worker file from `pdfjs-dist` relative to the current module:
import { pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.mjs',
import.meta.url,
).toString();The trap is placement. `workerSrc` must be set in the same module where you render `<Document>` and `<Page>`. If you set it once in an entry file such as `main.tsx` and import React-PDF in a different component, module execution order can let the default value overwrite your setting. The symptom is a worker that appears configured in code but is not the one PDF.js loads. Keep the assignment next to the components that use it.
Parcel 2 needs a slightly different specifier, prefixing the path with `npm:` so it reads `'npm:pdfjs-dist/build/pdf.worker.min.mjs'`.
Copying the worker or loading it from a CDN shifts the work to you
Two alternatives exist when bundler resolution does not fit. The first is to copy `pdf.worker.mjs` from `pdfjs-dist/build` into your build output yourself. React-PDF does not do this for you; one way is a small script:
import path from 'node:path';
import fs from 'node:fs';
const pdfjsDistPath = path.dirname(require.resolve('pdfjs-dist/package.json'));
const pdfWorkerPath = path.join(pdfjsDistPath, 'build', 'pdf.worker.mjs');
fs.cpSync(pdfWorkerPath, './dist/pdf.worker.mjs', { recursive: true });The cost is that the copy step becomes part of your build, and forgetting it after a `pdfjs-dist` upgrade leaves an old worker in `./dist`.
The second is an external CDN, with the version tied to the bundled PDF.js:
import { pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;This avoids bundling but makes every viewer load depend on unpkg.com being reachable from the user's network, and the same-module rule for `workerSrc` still applies.
Next.js and pnpm each need their own adjustment
In Next.js, the module that sets up the worker must be imported with server-side rendering skipped, using the lazy-loading options for either the Pages Router or the App Router. Projects on Next.js versions before 15, specifically before v15.0.0-canary.53, may also need to disable SWC minification in `next.config.js`:
module.exports = {
+ swcMinify: false,
}pnpm users can hit a different failure: the recommended worker import may not resolve `pdfjs-dist` unless pnpm hoists it. The fix depends on the pnpm version. Before pnpm 11, add this to `.npmrc`:
public-hoist-pattern[]=pdfjs-distWith pnpm 11 and later, the setting moves to `pnpm-workspace.yaml`:
publicHoistPattern:
- pdfjs-distThe repository ships sample apps for `next-app`, `next-pages`, `parcel2`, `vite` and `webpack5` under `sample/`, which are the quickest way to compare a broken setup against one that is wired correctly.
The legacy worker is a partial answer for older browsers
For older browsers, PDF.js publishes a legacy build, and React-PDF lets you point the worker at it by replacing `/build/` with `/legacy/build/` in the path:
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
- 'pdfjs-dist/build/pdf.worker.min.mjs',
+ 'pdfjs-dist/legacy/build/pdf.worker.min.mjs',
import.meta.url,
).toString();The CDN variant changes the same way, swapping `/build/pdf.worker.min.mjs` for `/legacy/build/pdf.worker.min.mjs` in the unpkg URL.
This is explicitly not a complete backwards-compatibility solution. Additional polyfills and bundler transpilation may still be required, and none of it lowers the stated minimums of Chrome 125 and Safari 18 for v11. If your audience includes browsers below those versions, the legacy worker will not rescue the integration on its own.
A Yarn 4 monorepo with the library under packages/
Contributors should know the repository layout before cloning. The root `package.json` is a monorepo named `react-pdf-monorepo` with workspaces for `packages/*` and `test`, and it pins `[email protected]` as the package manager. The publishable library is the `react-pdf` workspace: `yarn build` runs `yarn workspace react-pdf build`, and `yarn dev` runs the library in watch mode alongside the test workspace's dev server. Formatting, linting, type checks and unit tests fan out across all workspaces with `yarn workspaces foreach --all`, and a `postinstall` hook installs husky git hooks. Linting and formatting use Biome, configured in `biome.json`.
The project is MIT licensed and the last push landed on 2026-10-28.
Editorial conclusion
React-PDF is the right pick for a React 19 app that needs to show existing PDFs page by page with text and annotation layers, and it is free under MIT. It is the wrong pick for generating PDFs, which belongs to @react-pdf/renderer, and for projects pinned to older React or browsers below Chrome 125 and Safari 18, which should stay on a v10.x or earlier branch. Before adopting it, confirm you can set workerSrc in the same module that renders Document and that your bundler or package manager can resolve pdfjs-dist.
Frequently asked questions
Is React-PDF free?
Yes. wojtekmaj/react-pdf is released under the MIT license and installed from npm as react-pdf.
How do you install React-PDF?
Run npm install react-pdf or yarn add react-pdf, then configure the PDF.js worker in the same module where you render Document and Page. Version 11 needs React 19 or later and Node.js 22.13.0 or newer.
How do you use React-PDF in Next.js?
Import the module that renders React-PDF with SSR skipped, using the lazy-loading options of the Pages Router or App Router. On Next.js before v15.0.0-canary.53 you may also need swcMinify: false in next.config.js.
What is the difference between React-PDF and React PDF renderer?
react-pdf displays existing PDFs in a React app. @react-pdf/renderer is a separate npm package for creating PDFs with React.
What is React-PDF?
React-PDF is a library for displaying PDFs in React apps through Document and Page components built on PDF.js. Its file prop accepts a URL, base64 content, a Uint8Array and more.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/wojtekmaj-react-pdf)Star history chart for your README
[](https://hysenlabs.com/projects/wojtekmaj-react-pdf)Was this useful?