🌐
npm
npmjs.com › package › react-pdf
react-pdf - npm
Latest version: 10.2.0, last published: 2 months ago. Start using react-pdf in your project by running `npm i react-pdf`. There are 985 other projects in the npm registry using react-pdf.
      » npm install react-pdf
    
Published   Oct 09, 2025
Version   10.2.0
Author   Wojciech Maj
🌐
npm
npmjs.com › package › react-pdf-js
react-pdf-js - npm
Latest version: 5.1.0, last published: 6 years ago. Start using react-pdf-js in your project by running `npm i react-pdf-js`. There are 31 other projects in the npm registry using react-pdf-js.
      » npm install react-pdf-js
    
Published   Jun 19, 2019
Version   5.1.0
Author   mikecousins
🌐
GitHub
github.com › mikecousins › react-pdf-js
GitHub - mikecousins/react-pdf-js: A React component to wrap PDF.js
react-pdf-js provides a component for rendering PDF documents using PDF.js. ... Install with yarn add @mikecousins/react-pdf pdfjs-dist or npm install @mikecousins/react-pdf pdfjs-dist
Starred by 799 users
Forked by 151 users
Languages   TypeScript 90.7% | JavaScript 6.9% | CSS 2.0% | HTML 0.4%
🌐
React-pdf
react-pdf.org
React-pdf
React renderer for creating PDF files on the browser and server
🌐
GitHub
github.com › wojtekmaj › react-pdf
GitHub - wojtekmaj/react-pdf: Display PDFs in your React app as easily as if they were images.
This package is used to display existing PDFs. If you wish to create PDFs using React, you may be looking for @react-pdf/renderer. Install by executing npm install react-pdf or yarn add react-pdf.
Starred by 10.7K users
Forked by 981 users
Languages   TypeScript 94.3% | CSS 5.6% | HTML 0.1%
🌐
npm
npmjs.com › package › @react-pdf › renderer
@react-pdf/renderer - npm
Latest version: 4.3.1, last published: 3 months ago. Start using @react-pdf/renderer in your project by running `npm i @react-pdf/renderer`. There are 446 other projects in the npm registry using @react-pdf/renderer.
      » npm install @react-pdf/renderer
    
Published   Sep 23, 2025
Version   4.3.1
Author   Diego Muracciole
🌐
npm
npmjs.com › package › react-to-pdf
react-to-pdf - npm
Create PDF documents from React Components. Latest version: 2.0.3, last published: 17 days ago. Start using react-to-pdf in your project by running `npm i react-to-pdf`. There are 28 other projects in the npm registry using react-to-pdf.
      » npm install react-to-pdf
    
Published   Nov 25, 2025
Version   2.0.3
Author   Marcos Andrei Ivanechtchuk
🌐
npm
npmjs.com › package › @pdf-viewer › react
@pdf-viewer/react - npm
Latest version: 1.13.1, last published: 5 days ago. Start using @pdf-viewer/react in your project by running `npm i @pdf-viewer/react`. There are no other projects in the npm registry using @pdf-viewer/react.
      » npm install @pdf-viewer/react
    
Published   Dec 04, 2025
Version   1.13.1
Author   React PDF Viewer
🌐
Nutrient
nutrient.io › blog › sdk › how to build a reactjs pdf viewer with react pdf
React PDF viewer: Complete guide to building with react-pdf in 2025
August 12, 2025 - To create a React PDF viewer with react-pdf: 1) Install the library (npm install react-pdf), 2) Import Document and Page components, 3) Configure the PDF.js worker, and 4) Build your own UI controls.
Find elsewhere
🌐
npm
npmjs.com › package › @mikecousins › react-pdf
@mikecousins/react-pdf - npm
Latest version: 8.0.1, last published: 6 months ago. Start using @mikecousins/react-pdf in your project by running `npm i @mikecousins/react-pdf`. There are 11 other projects in the npm registry using ...
      » npm install @mikecousins/react-pdf
    
Published   Mar 28, 2025
Version   8.0.1
Author   mikecousins
🌐
npm
npmjs.com › package › @react-pdf-viewer › core
@react-pdf-viewer/core - npm
Latest version: 3.12.0, last published: 3 years ago. Start using @react-pdf-viewer/core in your project by running `npm i @react-pdf-viewer/core`. There are 167 other projects in the npm registry using @react-pdf-viewer/core.
      » npm install @react-pdf-viewer/core
    
Published   Mar 21, 2023
Version   3.12.0
Author   Nguyen Huu Phuoc
🌐
Nutrient
nutrient.io › blog › sdk › how to build a reactjs viewer with pdfjs
Build a React PDF viewer with PDF.js and Next.js: Step-by-step tutorial
July 16, 2025 - Learn how to build a fast, customizable PDF viewer in React using PDF.js and Next.js. Includes full code examples, setup instructions, and a comparison with Nutrient’s feature-rich PDF SDK.
🌐
npm
npmjs.com › package › jspdf-react
jspdf-react - npm
Wrapper jsPDF for React. Latest version: 1.0.11, last published: 6 years ago. Start using jspdf-react in your project by running `npm i jspdf-react`. There are 7 other projects in the npm registry using jspdf-react.
      » npm install jspdf-react
    
Published   Jul 17, 2019
Version   1.0.11
Author   apipemc
🌐
npm
npmjs.com › package › react-view-pdf
react-view-pdf - npm
Latest version: 1.0.0, last published: 4 years ago. Start using react-view-pdf in your project by running `npm i react-view-pdf`. There are no other projects in the npm registry using react-view-pdf.
      » npm install react-view-pdf
    
Published   Nov 24, 2021
Version   1.0.0
Author   ZEISS Digital Innovation Partners
🌐
npm
npmjs.com › package › react-pdf-html
react-pdf-html - npm
Parses the HTML string into a JSON tree of nodes using node-html-parser · Parses any <style> tags in the document and style attributes using css-tree · Renders all nodes using the appropriate react-pdf components, applying cascading styles ...
      » npm install react-pdf-html
    
Published   Jan 15, 2025
Version   2.1.3
Author   Dan Blaisdell [email protected]
Top answer
1 of 5
25

I spent too much time today, piecing together fragments of other answers to this question. So here is a complete answer.

First you install pdfjs-dist:

npm install pdfjs-dist

And here is how to use it in an actual viewer component:

import React, { useEffect, useState, useRef, useCallback } from 'react';
import pdfjsLib from "pdfjs-dist/build/pdf";
import pdfjsWorker from "pdfjs-dist/build/pdf.worker.entry";

export default function PdfViewer({url}){
  const canvasRef = useRef();
  pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker;

  const [pdfRef, setPdfRef] = useState();
  const [currentPage, setCurrentPage] = useState(1);

  const renderPage = useCallback((pageNum, pdf=pdfRef) => {
    pdf && pdf.getPage(pageNum).then(function(page) {
      const viewport = page.getViewport({scale: 1.5});
      const canvas = canvasRef.current;
      canvas.height = viewport.height;
      canvas.width = viewport.width;
      const renderContext = {
        canvasContext: canvas.getContext('2d'),
        viewport: viewport
      };
      page.render(renderContext);
    });   
  }, [pdfRef]);

  useEffect(() => {
    renderPage(currentPage, pdfRef);
  }, [pdfRef, currentPage, renderPage]);

  useEffect(() => {
    const loadingTask = pdfjsLib.getDocument(url);
    loadingTask.promise.then(loadedPdf => {
      setPdfRef(loadedPdf);
    }, function (reason) {
      console.error(reason);
    });
  }, [url]);

  const nextPage = () => pdfRef && currentPage < pdfRef.numPages && setCurrentPage(currentPage + 1);

  const prevPage = () => currentPage > 1 && setCurrentPage(currentPage - 1);

  return <canvas ref={canvasRef}></canvas>;
}
2 of 5
9

This import will clear the undefined issue:

import * as pdfjsLib from "pdfjs-dist/build/pdf";
🌐
React PDF Viewer
react-pdf-viewer.dev › docs › getting-started
Getting started - React PDF Viewer
npm install [email protected] · The `pdfjs-dist` will be added to the `dependencies` section in `package.json`: { "dependencies": { "pdfjs-dist": "^3.4.120" } } If the installed version of `pdfjs-dist` requires the canvas package which has issues with Apple M1.
🌐
PDF.js Express
pdfjs.express › documentation › get-started › react
Integrate React & JavaScript PDF Viewer | PDF.js Express SDK
const MyComponent = () => { const viewer = useRef(null); useEffect(() => { WebViewer( { path: '/webviewer/lib', initialDoc: '/files/pdftron_about.pdf', }, viewer.current, ).then((instance) => { }); }, []); return ( <div className="MyComponent"> <div className="header">React sample</div> <div className="webviewer" ref={viewer}></div> </div> ); }; Run the app by running npm start.
🌐
GitHub
github.com › erikras › react-pdfjs
GitHub - erikras/react-pdfjs: A React component to wrap PDF.js
react-pdfjs provides a component for rendering PDF documents using PDF.js. npm install --save react-pdfjs · This project will not be supported. It is a port of react-pdf to ES6 and React 0.14.
Starred by 82 users
Forked by 25 users
Languages   JavaScript
🌐
Stack Overflow
stackoverflow.com › questions › 73919619 › how-to-use-pdf-js-with-react
reactjs - How to use PDF.JS with React? - Stack Overflow
export default function Home() { const [data, setData] = useState(); const handleFile = (e) => { const file = e.target.files[0]; const fileReader = new FileReader(); fileReader.onload = (d) => { setData(new Uint32Array(d.target.result)); }; }; return ( <> <h1>hello!</h1> <input type="file" accept="application/pdf" placeholder="insert PDF here" onChange={(e) => handleFile(e)} /> <PDFViewer pdfFile={data} /> </> ); }