Web显示pdf文件(兼容IE)

# fixed version can't change
$ npm install [email protected]
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)
    })
  }
})

你可能感兴趣的:(Web显示pdf文件(兼容IE))