React pdf kit setup
Skills to help developers using AI agents with React PDF Kit library
npx -y skills add react-pdf-kit/agent-skills --skill react-pdf-kit-setupAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Set up @react-pdf-kit/viewer in a generic React app (>=2.0.0 <3.0.0) using the canonical RPConfig, RPProvider, RPLayout, RPPages provider chain.
SKILL.md
3.8 KB, as published. Nobody here has run it
react-pdf-kit-setup
Use this skill when: the developer asks to add a PDF viewer using
@react-pdf-kit/viewer to a React project, AND the project is not
specifically Next.js or Vite. For those, prefer the framework-specific
skills.
@react-pdf-kit/viewer builds on PDF.js and renders PDFs through a
nested provider chain. Treat the chain as the canonical composition
model. Everything else (theming, layout, hooks) layers onto it.
Gotchas
- Install only
@react-pdf-kit/viewer. Do NOT installpdfjs-distseparately. In v2,pdfjs-distis an auto-installed peer dependency pinned to a default version (5.4.530). You installpdfjs-distyourself ONLY when deliberately overriding that version, which is covered byreact-pdf-kit-worker-config. RPConfigconfigures the PDF.js worker for you. The worker is set up automatically. Do NOT setGlobalWorkerOptions.workerSrcor pass aworkerUrl. Custom worker URLs are only needed when overridingpdfjs-dist; seereact-pdf-kit-worker-config.RPConfigbelongs at the root and should be rendered once. It also wraps theming internally, so a separateRPThemeis optional.licenseKeyonRPConfigis optional. Without it the viewer runs in free/trial mode (a watermark is shown). Pass<RPConfig licenseKey="...">for licensed/commercial use.- CSS is auto-injected by the library. Do NOT import a separate stylesheet.
RPDefaultLayoutis deprecated in v2. UseRPLayoutfor every new integration.
Procedure
1. Install the library
pnpm add @react-pdf-kit/viewer
(Use npm install, yarn add, or bun add if not on pnpm.) Nothing
else is required; pdfjs-dist is pulled in automatically.
2. Add RPConfig at the app root
RPConfig must be rendered once at the root of your application. It
handles worker setup and theming for every viewer instance below it.
// src/App.tsx
import { RPConfig } from '@react-pdf-kit/viewer'
import { PdfViewer } from './PdfViewer'
export function App() {
return (
<RPConfig>
<main style={{ height: '100vh' }}>
<PdfViewer src="/sample.pdf" />
</main>
</RPConfig>
)
}
For explicit theme control, pass customVariables / customDarkVariables
to RPConfig (or nest an RPTheme).
3. Render the viewer with the provider chain
// src/PdfViewer.tsx
import {
RPProvider,
RPLayout,
RPPages,
} from '@react-pdf-kit/viewer'
export function PdfViewer({ src }: { src: string }) {
return (
<RPProvider src={src}>
<RPLayout toolbar>
<RPPages />
</RPLayout>
</RPProvider>
)
}
RPLayout's toolbar prop renders the default toolbar. The viewer
adapts to its container, so give the parent a definite height (100vh
or fixed) for virtual scrolling to work. You can also size it directly
via RPLayout's style prop.
Verify
pnpm install
pnpm build
pnpm dev
Open the dev server URL. The first PDF page should render with the default toolbar visible. Scroll down. Additional pages mount as you scroll (virtualization at work). Selecting text should produce a real text selection, not a canvas-only image.
References
- Library README: https://github.com/react-pdf-kit/viewer
- Companion skills:
react-pdf-kit-nextjs-app-routerfor Next.js App Router projects.react-pdf-kit-vitefor Vite projects.react-pdf-kit-worker-configfor overriding thepdfjs-distversion and configuring a custom worker URL.