I am using pdf.js (version 3.6.172) in a project and are trying to use react-pdf (version 6.2.2).
The problem is setting workerSrc
as each package tries to use their own version and refuses to use a wrong version.
To load pdf.js I use:
import * as pdfjsLib from 'pdfjs-dist';
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry';
and then, set workerSrc:
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker;
In the component that uses react-pdf
, I use:
import { Document, Page, pdfjs } from 'react-pdf';
import pdfjsWorker from "react-pdf/node_modules/pdfjs-dist/build/pdf.worker.entry";
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;
If I comment the react-pdf code, the pdf.js code works flawlessly. The same happens otherwise (when I comment the pdf.js code, the react-pdf code works OK).
Is there a way to both libraries be loaded in the same project?