My version of pdfjs-dist: "pdfjs-dist": "^2.4.456"
This is import my code:
import PDFJS from 'pdfjs-dist'
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry'
and when I call :
PDFJS.GlobalWorkerOptions.workerSrc = pdfjsWorker
this.loadingTask = PDFJS.getDocument({ data: self.pdfData })
It return this error: [TypeError: Cannot read property 'GlobalWorkerOptions' of undefined]
PDFJS
, it return undefinded
So when I try this solution in the internet, I add
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.5.207/pdf.min.js"></script>
in my index.html
and
add var PDFJS = window['pdfjs-dist/build/pdf'];
Then it works perfectly...But I dont know why the first approach doesn't work for me...And I do not want use this from CDN because I think it's not stable for my project.
So could you guys give me a point what I missed here? I tried to look around in node-modules
to figure out but I still do not why i can't import PDFJS from 'pdfjs-dist'
;
I SOLVED MY PROBLEM
I do not know if it is the root of problem or not, but I just simple change from
import PDFJS from 'pdfjs-dist'
to import * as PDFJS from 'pdfjs-dist'
, and it work perfectly.