pdf-viewport
A library that makes using pdfjs in react projects easy.
Getting Started
Add pdfjs-dist
and pdf-viewport
as dependencies:
Set pdfjsLib.GlobalWorkerOptions.workerSrc
. You could for example use a hosted variant of the worker or use worker-loader
to bundle the worker yourself using webpack.
Load the PDF using getDocument
from pdfjs. You can do this e.g. using useEffect
or react-query:
Now you can use pdf-viewport
to render the PDF using one of its components: