# fixed version can't change
$ npm install pdfjs-dist@2.0.943
import PDF from 'pdfjs-dist'
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry'
PDF.GlobalWorkerOptions.workerSrc = pdfjsWorker
PDF.getDocument(file).then((pdf) => {
// create canvas dom
// after dom rendered
for (let i = 0; i < pdf.numPages; i++) {
pdf.getPage(i + 1).then((page) => {
const viewport = page.getViewport(1.5)
const canvas = document.getElementById('canvas dom id')
const context = canvas.getContext('2d')
canvas.height = viewport.height
canvas.width = viewport.width
const renderContext = {
canvasContext: context,
viewport: viewport,
}
page.render(renderContext)
})
}
})