@plp-sergio/react-reader
v0.4.7
Published
A React reader for PDFs and image publications with navigation, zoom, and search.
Readme
React Reader
A React reader for PDFs and image-based publications, with page navigation, zoom, search, thumbnails, and mobile gestures.
Install
npm install @plp-sergio/react-readerFor PDF support, also install:
npm install [email protected]Supports React 18 and 19. Use a client component in Next.js.
Open a PDF or publication
'use client';
import { Reader } from '@plp-sergio/react-reader/reader';
import '@plp-sergio/react-reader/styles.css';
export default function Book() {
return (
<Reader
src="/books/example.pdf"
title="My publication"
locale="en"
style={{ height: '100dvh' }}
/>
);
}src accepts a PDF path or an edition folder such as /publications/publication-id/edition-id/. Folder mode first tries an optional publication.json manifest, then the supported numbered image, BIN, and PDF naming conventions. Missing or unusable manifests fall back automatically, preserving the current page. Direct PDF URLs still open the PDF first. Image editions prepare a buffer of ten pages around the starting spread (or every page in shorter editions), then open the reader and continue warming the remaining images and text in the background. The loading screen shows preparation stages and actual page progress.
For PDF rendering, serve the matching PDF.js files from /pdfjs/: pdf.worker.min.mjs from its build/ directory, plus the cmaps/, standard_fonts/, wasm/, and iccs/ directories. Set pdfAssetsUrl if you use a different location. The PDF dependency requires Node 22.13+ or 24+.
Open image pages
import { Flipbook } from '@plp-sergio/react-reader';
import '@plp-sergio/react-reader/styles.css';
<Flipbook
title="My publication"
locale="en"
pages={[
{ src: '/books/page-1.jpg', alt: 'Cover' },
{ src: '/books/page-2.jpg', alt: 'Page 2' },
]}
/>Image-only use does not require PDF.js. Search needs supplied page text or extractable PDF text; the reader does not perform OCR.
Clickable page links
Edition and PDF readers automatically try the optional UI_Zine.xml file beside the publication. By default, they use its clickable page links while keeping the reader's normal toolbar, navigation, and appearance. Missing or invalid XML does not stop reading.
For a direct image list, pass uiConfigUrl="/books/UI_Zine.xml" to Flipbook. Set uiConfigMode="full" to apply its configured controls and styling. Use uiConfigUrl={false} to skip the file entirely. Edition loading, PDF rendering and XML integration are supported parts of the main reader.
Page changes use a 3D paper bend with the page artwork and painted text together. Three.js loads on the first animated turn; indexed geometry and a bounded texture cache are reused, with no rendering at rest. Single pages, spreads and right-to-left reading retain the existing navigation controls. Reduced motion and disabled page animation skip the renderer. When WebGL is unavailable or cross-origin artwork cannot safely become a texture, the existing DOM transition remains available. Hosted images can also use the bend when their server permits anonymous CORS access; the overlay tries that separately without changing the displayed image request. Servers that deny CORS retain the fallback transition. Moving surfaces use a 1.5 pixel-ratio cap and smaller shadows; resting pages keep their original rendering.
Common options
| Option | Purpose |
| --- | --- |
| title | Publication name. |
| locale | es (default), en, or auto. |
| initialPage | Starting page, numbered from 1. |
| onPageChange | Receive the current page number. |
| initialTheme | portal, paper, sepia, or night. |
| initialPageTurnAnimation | Enable or disable page transitions. |
After the visible pages finish loading, image readers warm nearby pages first and then continue through the publication with at most two background requests. Navigation gives the new page priority. Split PDFs warm remaining files after preparing nearby pages; full PDFs retain PDF.js streaming. Large rendered pages stay in a bounded cache. Configure HTTP caching on your asset host so downloaded assets can be reused during later navigation.
Reader also accepts style, className, and pdfAssetsUrl. Flipbook provides controlled page and layout options, callbacks, and navigation methods through a ref.
Hosting
Use your own document and asset paths. Cross-origin files must allow the browser's requests. Keep private publications behind your application's access controls. The reader does not provide authentication or host documents.
CloudFront testing example
For a phone or another device on the same network, open the CloudFront / LAN URL printed by npm run dev. You can add &publicationId=421&issueId=10205 to open an issue directly. The dev server listens on all network interfaces.
Run npm run dev and open http://localhost:5173/?cloudfront. Enter a publication ID and issue ID to load https://d37w6g2wghq2wf.cloudfront.net/{publicationId}/{issueId}/ with the existing automatic reader. Submitting updates the page URL so you can share or reload the same issue; submitting again reloads it.
You can also open http://localhost:5173/?cloudfront&publicationId=YOUR_PUBLICATION&issueId=YOUR_ISSUE directly. The development server serves the installed PDF.js assets for PDF fallback. Remote assets must allow browser cross-origin requests. Open / for sample pages, /?open for a manifest URL or file, or /?src=<publication-url> for automatic source selection.
Advanced usage
The reference guide covers edition folders, manifests, text layers, migration, and the full API. It is also included in the installed package at docs/REFERENCE.md.
License
MIT. Document content, images, and fonts retain their owners' licenses.
