Shipping PDFs in modern interfaces demands more than a download button. From generating contracts to previewing reports, React teams balance speed, accessibility, and pixel precision. This guide maps the common paths—generation, viewing, and quick embedding—so you can choose the right approach without reinventing the rendering wheel.
Documentation and API reference: react-pdf
Two core use-cases
- React pdf for document generation: Compose PDFs with React components and deterministic styling, ideal for invoices, labels, statements, and forms.
- In-app viewing: Add a feature-rich React pdf viewer experience—pagination, zoom, thumbnails, search—so users don’t leave your app. Some teams prefer modular viewers like react-pdf-viewer for pluggable toolbar controls and customization.
Fast paths to preview: when you need to react show pdf or react display pdf
- Embed quickly with iframe/object
- Pros: zero dependencies; works with browser-native PDF viewer
- Cons: inconsistent controls across browsers; limited customization
- Canvas-based rendering (PDF.js wrappers)
- Pros: consistent look; full control of toolbar and layout
- Cons: heavier bundle; needs workers and caching for performance
- Server-side render to image
- Pros: stable previews; fast initial paint
- Cons: not selectable text; separate flow for full-fidelity print
Decision guide
- Choose generation (React pdf) when you control the document schema and need consistent print output.
- Choose a viewer (React pdf viewer / react-pdf-viewer) when users must read, search, or annotate PDFs inside your app.
- Choose quick embed when time-to-market beats customization.
Performance playbook
- Lazy-load the viewer and use a web worker for parsing.
- Virtualize pages; render only visible pages and prefetch the next ones.
- Cache document byte ranges; enable range requests on your CDN.
- Throttle reflows on zoom; debounce scroll-driven re-render.
- Defer heavy features (thumbnails, text layers) behind interaction.
Accessibility and UX must-haves
- Keyboard navigation: next/previous page, zoom in/out, search focus.
- High-contrast toolbar icons and large hit targets.
- Search with highlight announcements for screen readers.
- Download/Print buttons with clear affordances and fallback.
- Page number input with validation and ARIA live regions.
Security and compliance notes
- Enable CORS and Content Security Policy for worker scripts.
- Sanitize URLs; disallow javascript: and data: schemes from user input.
- Protect sensitive PDFs with signed URLs and short TTLs.
- Consider redaction pipelines before display to remove PII.
Integration checklist
- Decide: generation (React pdf) vs viewing (React pdf viewer/react-pdf-viewer) vs simple embed.
- Set up lazy loading and a skeleton placeholder for the viewer.
- Add keyboard shortcuts and focus management.
- Implement progressive loading and page virtualization.
- Offer download/print and error recovery (retry, offline message).
- Measure: time-to-first-page, memory footprint, and scroll jank.
FAQs
Can I generate and preview with the same stack?
Yes. Many teams generate with React pdf and preview the output using a React pdf viewer for a consistent workflow.
What’s the quickest way to react show pdf from a URL?
Start with an iframe/object for minimal setup, then upgrade to a viewer if you need search, thumbnails, or consistent controls.
How do I make large documents smooth to scroll?
Use virtualization (render visible pages only), enable range requests on your server/CDN, and parse in a worker to keep the UI thread responsive.
Is text selectable and searchable?
With canvas-based viewers, enable text layers to preserve selection and search. If you server-render to images, you’ll lose selectable text.
How do I react display pdf offline?
Cache the document with a service worker and store recent pages in IndexedDB. Provide a clear offline banner and a retry mechanism.
