Skip to content
Legacy Browser Support

@react-pdf-kit/viewer relies on modern browser APIs. If your users are on older browsers, there are two methods you can choose from:

  1. Polyfills: Load the dedicated @react-pdf-kit/polyfills package to support older browsers
  2. Polyfills and Legacy PDF.js Worker: Load the @react-pdf-kit/polyfills and override with a Legacy PDF.js Worker to support even more older browsers than the first method.

@react-pdf-kit/polyfills package is used to fill in gaps of certain functions in older browsers before any viewer code runs. The bundle is kept in a separate package so it can be versioned independently from the viewer.

The polyfills library will support the following browsers:

ChromeFirefoxEdgeSafariSafari iOSChrome Android
119+93+119+18.3+18.3+119+

For standard React apps, importing the package at the top of your entry point is all that is needed. The side-effect import runs the polyfills synchronously before the rest of the module graph executes.

  1. Install @react-pdf-kit/polyfills:

    Terminal window
    pnpm add @react-pdf-kit/polyfills
  2. Import the package at the very top of your entry file, before any other imports:

    src/main.jsx
    import '@react-pdf-kit/polyfills'
    import React from 'react'
    import ReactDOM from 'react-dom/client'
    import App from './App'
    ReactDOM.createRoot(document.getElementById('root')).render(
    <React.StrictMode>
    <App />
    </React.StrictMode>
    )

Next.js automatically replaces polyfill imports with its own built-in polyfills at compile time, so a bare import '@react-pdf-kit/polyfills' will never execute. To work around this, the polyfills bundle is copied to public/ at build time and loaded via a <Script> component with strategy="beforeInteractive", which bypasses Next.js’s polyfill substitution and ensures the bundle runs before hydration.

  1. Install @react-pdf-kit/polyfills.

    Terminal window
    pnpm add @react-pdf-kit/polyfills
  2. Copy the bundle at build time in next.config.mjs:

    next.config.mjs
    import { copyFileSync } from 'fs'
    import { resolve } from 'path'
    copyFileSync(
    resolve(__dirname, 'node_modules/@react-pdf-kit/polyfills/dist/index.cjs.js'),
    resolve(__dirname, 'public/polyfills.js'),
    )
    /** @type {import('next').NextConfig} */
    const nextConfig = {
    // ...your config
    }
    export default nextConfig

    This runs once during the build and places the bundle at public/polyfills.js so Next.js serves it as a static file.

  3. Create a Polyfills component that loads the script before any other JavaScript:

    app/_components/PdfViewer/Polyfills.jsx
    import Script from 'next/script'
    export default function Polyfills() {
    return <Script src="/polyfills.js" strategy="beforeInteractive" />
    }
  4. Render <Polyfills /> in your root layout so it applies to every page:

    app/layout.jsx
    import Polyfills from './_components/PdfViewer/Polyfills'
    export default function RootLayout({ children }) {
    return (
    <html lang="en">
    <body>
    <Polyfills />
    {children}
    </body>
    </html>
    )
    }

The standard PDF.js worker tend to support on modern browsers only. You can install @react-pdf-kit/polyfills together with the legacy PDF.js worker build to extend browser compatibility.

This method will support the following browser as shown below:

ChromeFirefoxEdgeSafariSafari iOSChrome Android
101+101+101+16.5+16.5+101+
  1. It’s important to complete the first method of installing the Polyfills library.

  2. Install pdfjs-dist:

    Terminal window
    pnpm add pdfjs-dist
  3. Pass the legacy worker URL to RPConfig via the workerUrl prop:

    app/components/AppProviders.jsx
    import { RPConfig } from '@react-pdf-kit/viewer'
    const workerSrc = new URL(
    'pdfjs-dist/legacy/build/pdf.worker.min.mjs',
    import.meta.url,
    ).toString()
    export default function AppProviders({ children, ...props }) {
    return (
    <RPConfig workerUrl={workerSrc} {...props}>
    {children}
    </RPConfig>
    )
    }