Gathering detailed insights and metrics for @mikecousins/react-pdf
Gathering detailed insights and metrics for @mikecousins/react-pdf
Gathering detailed insights and metrics for @mikecousins/react-pdf
Gathering detailed insights and metrics for @mikecousins/react-pdf
npm install @mikecousins/react-pdf
Typescript
Module System
Node Version
NPM Version
TypeScript (90.73%)
JavaScript (6.9%)
CSS (2%)
HTML (0.37%)
Total Downloads
1,775,641
Last Day
215
Last Week
10,590
Last Month
46,674
Last Year
545,742
MIT License
786 Stars
597 Commits
151 Forks
13 Watchers
11 Branches
29 Contributors
Updated on Aug 25, 2025
Latest Version
8.0.1
Package Id
@mikecousins/react-pdf@8.0.1
Unpacked Size
17.79 kB
Size
3.98 kB
File Count
6
NPM Version
10.9.2
Node Version
23.10.0
Published on
Mar 28, 2025
Cumulative downloads
Total Downloads
Last Day
-12.6%
215
Compared to previous day
Last Week
-5.2%
10,590
Compared to previous week
Last Month
2.2%
46,674
Compared to previous month
Last Year
61%
545,742
Compared to previous year
react-pdf-js
provides a component for rendering PDF documents using PDF.js.
Install with pnpm add @mikecousins/react-pdf pdfjs-dist
, yarn add @mikecousins/react-pdf pdfjs-dist
or npm install @mikecousins/react-pdf pdfjs-dist
usePdf
hookUse the hook in your app (showing some basic pagination as well):
1import React, { useState, useRef } from 'react'; 2import { usePdf } from '@mikecousins/react-pdf'; 3 4const MyPdfViewer = () => { 5 const [page, setPage] = useState(1); 6 const canvasRef = useRef(null); 7 8 const { pdfDocument, pdfPage } = usePdf({ 9 file: 'test.pdf', 10 page, 11 canvasRef, 12 }); 13 14 return ( 15 <div> 16 {!pdfDocument && <span>Loading...</span>} 17 <canvas ref={canvasRef} /> 18 {Boolean(pdfDocument && pdfDocument.numPages) && ( 19 <nav> 20 <ul className="pager"> 21 <li className="previous"> 22 <button disabled={page === 1} onClick={() => setPage(page - 1)}> 23 Previous 24 </button> 25 </li> 26 <li className="next"> 27 <button 28 disabled={page === pdfDocument.numPages} 29 onClick={() => setPage(page + 1)} 30 > 31 Next 32 </button> 33 </li> 34 </ul> 35 </nav> 36 )} 37 </div> 38 ); 39};
When you call usePdf you'll want to pass in a subset of these props, like this:
const { pdfDocument, pdfPage } = usePdf({ canvasRef, file: 'https://example.com/test.pdf', page });
A reference to the canvas element. Create with:
const canvasRef = useRef(null);
and then render it like:
<canvas ref={canvasRef} />
and then pass it into usePdf.
URL of the PDF file.
Allows you to specify a callback that is called when the PDF document data will be fully loaded. Callback is called with PDFDocumentProxy as an only argument.
Allows you to specify a callback that is called after an error occurred during PDF document data loading.
Allows you to specify a callback that is called when the PDF page data will be fully loaded. Callback is called with PDFPageProxy as an only argument.
Allows you to specify a callback that is called after an error occurred during PDF page data loading.
Allows you to specify a callback that is called when the PDF page will be fully rendered into the DOM. Callback is called with PDFPageProxy as an only argument.
Allows you to specify a callback that is called after an error occurred during PDF page rendering.
Specify the page that you want to display. Default = 1,
Allows you to scale the PDF. Default = 1.
Allows you to rotate the PDF. Number is in degrees. Default = 0.
Allows you to specify a cmap url. Default = '../node_modules/pdfjs-dist/cmaps/'.
Allows you to specify whether the cmaps are packed or not. Default = false.
Allows you to specify a custom pdf worker url. Default = '//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js'.
Allows you to add the withCredentials flag. Default = false.
pdfjs
's PDFDocumentProxy
object.
This can be undefined if document has not been loaded yet.
pdfjs
's PDFPageProxy
object
This can be undefined if page has not been loaded yet.
MIT © mikecousins
No vulnerabilities found.